【发布时间】:2014-04-16 03:52:10
【问题描述】:
因此,我的程序旨在为用户提供出色的服务并要求输入密码。一旦用户输入密码,它将与我的预编码密码“ans[]”进行比较,如果密码与用户输入的密码匹配,则打印欢迎问候语。
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(int argc, const char * argv[])
{
char hello[] = "Hello! \nPassword Required:";
char password[50];
char ans[] = "Zanderg!";
printf(hello);
printf("\n");
gets(password);
if (strcmp(password, ans) != 0) {
do {
printf("%s Not correct.\n", password);
printf("Enter Password:\n");
gets(password);
getchar();
}while (strcmp(password, ans) != 0);
};
if (strcmp(password, ans) == 0) {
printf("welcome %s", password);
}
}
我的问题是,当我输入正确的密码时,我仍然收到“密码错误”的消息。
我也收到了一条关于gets() 不安全的非常奇怪的消息,我想知道是否有其他gets() 的替代方法,或者如何在我的程序中消除此错误消息。我的编译器是 Xcode。
【问题讨论】:
-
你的程序在我的系统(gcc)上运行。您使用的是哪个编译器?
-
是的,它曾经工作过一次,但自从......我已经改变了任何东西,所以我不确定问题是什么。我正在使用 Xcode @SGG
-
没关系...我发现了问题。 @SGG
-
+if 语句后加分号
-
@Zanderg 有什么问题?