C语言初学者问一个非常简单的问题!!在线求助~

2025-03-01 13:03:13
推荐回答(1个)
回答1:

Please enter the password!:Who is my favourite basketball player?
************
You are welcome!
Press any key to continue

#include
#include
#include //我VC6 没这个编译不过 你没有可以编译过的可以不加
main()
{
char str1[30]="Lebron James";
char str2[30]=" ";
int n=1,i;
printf("Please enter the password!:Who is my favourite basketball player?\n");
//gets(str2);
for(i=0;i<12;i++) //你如果<=30 那么也就是说后面包括\0什么的都需要输入
{
str2[i]=getch();
if(str2[i]=='\r')
{
break;
}
printf("*");
}
printf("\n");
while(strcmp(str1,str2)!=0&&n<=2)
{
printf("Wrong!You have entered %d times!\n",n);
printf("Please enter the password again!\n");
gets(str2);
n++;
}
if(strcmp(str1,str2)!=0){printf("You have entered 3 times! You are not welcome£?\n");}
if(strcmp(str1,str2)==0){printf("You are welcome!\n");}
}