编写代码,模拟用户登录的情景,并且只能登陆三(只能输入三次密码,如果密码正确则提示登陆成功,如果三次均输入错误,则登录失)
#include<stdio.h>
#include<string.h>
int main()
{
char a1[]={"abc"};
char a2[]={"0"};
int i=1;
while(i<=3)
{
scanf("%s",&a2);
if(strcmp(a2,"abc")==0)
{
printf("yes");
break;
}
if(strcmp(a2,"abc")!=0)
{
printf("cuowu\n");
i++;
if(i>3)
break;
}
}
return 0;
}
abc
yes
--------------------------------
Process exited after 2.361 seconds with return value 0
Press any key to continue . . .
库函数strcmp():用于比较两个字符串是否相等,若相等则返回0