The control password can only be entered three times
We often log in to some websites and find that if we enter the wrong password several times in a row, our account is locked. How is this process achieved? Let’s take a brief look at
this program to solve the problem. The following 3 things:
1. Enter the user name and password
2. The authentication is successful and the welcome message is displayed
3. The lock is locked after three incorrect input
#include<stdio.h>
#include<string.h>
int main()
{
int n = 2;
while (n>=0)
{
char passwdArr[20] = {
0};
printf("请输入密码:\n");
scanf("%s", passwdArr);
if (strcmp(passwdArr, "1024haha") == 0)
{
printf("登陆成功\n");
break;
}
else
{
printf("密码错误,请重新输入注意你还有%d次机会\n",n);
}
--n;
}
return 0;
}