运行代码:
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(vodi)
{
//5.模拟用户登录情况,并且只能登录三次
//(只允许输入三次密码,如果密码正确,则提示登录成功,若三次均输入错误,则退出程序)
int i = 0;
char passward[20] = { 0 };
while (i < 3)
{
scanf("%s", passward);
if (strcmp(passward, "abcdef") == 0)
{
printf("Right!\n");
break;
}
else
printf("ERROR!Enter again!\n");
i++;
}
if(3==i)
printf("The input is incorrect for three times!\n");
return 0;
}
PS:调用strcmp时记得要用#include<string.h>头文件