设置登录密码,有且只有三次机会
运用到了strcmp函数
直接上代码
#include<stdio.h>
#include<string.h>
int main()
{
int n=0;
char pasword[20]={0};
for(n=0;n<3;n++)
{
printf("请输入密码:>");
scanf("%s",pasword);
if(strcmp(pasword,"123456")==0) //密码设置为123456
{
printf("密码正确!");
break;
}
else
{
printf("密码输入错误,请重新输入!\n");
}
}
while(n==3)
{
printf("三次密码全都输入错误,密码锁定!\n");
break;
}
return 0;
}
strcmp函数解释
1.strcmp在文件<string.h>中,所以要引用头文件#include<string.h>
2.strcmp比较的两个字符串,比较的是ASCII码值。
3.当两个字符串相等时,strcmp(字符串1,“字符串2”)==0;
选择和循环语句
剩下的为一些简单的循环和选择语句,如若不懂,在评论区留言,我会为你解答。
学的不是技术,更是梦想