很简单的程序:
int main (void)
{
int i = 0, length=0;
char password[] = SECRET;
char guess[10];
for (i=0; i<3; i++){
printf( "Enter the password: " );
fgets (guess, 10, stdin );
length=strlen(guess);
guess[length]='\0';
if(strcmp( guess, password ) == 0 ){
printf("\aYou got it right!\n" );
return 0;
}
else printf("You wrote %s Incorrect guess\n\n", guess);
}
puts("Sorry, you're all out of guesses");
return 0;
}
但它不起作用。
即使在我可以让程序说的奇怪情况下:“你猜是'黑色'。对不起,密码是'黑色'” 认为某些隐藏字符,空格,垃圾信息或其他任何东西可能存在问题字符串比较,但我似乎找不到它是什么!