c语言口令检查并限制次数输入

来源:互联网 发布:中国移动网络测速 编辑:程序博客网 时间:2024/04/29 13:00
#include "stdio.h"
#include "string.h"
#include "conio.h"
#include "stdlib.h"

#define PASSWORD "987654"  //正确密码

void Error();//循环函数
int n=0;//全局循环计次
char* input()
{
char account_name[256];//帐号
char password_pas[256];//密码
int i=0;
printf("输入帐号:");
scanf("%s",account_name);

printf("输入密码:");
while((password_pas[i]=getch())!='\r')//输入的密码不回车时
{
if(password_pas[i]!='\b')//密码不等于退格键时
{
i++;
printf("*");
}
else
{
printf("\b \b");//清空最多到没有字符
i--;
}
}
password_pas[i]='\0';//加上结束字符
if((strcmp(password_pas,PASSWORD))!=0)
{
printf("\n");
printf("离我远点!\n");
Error();//当错误时,调用循环计次函数
}
else
{
printf("\n");
printf("您好,主人!\n");
}
return password_pas;//返回密码
}

void Error()
{
char* p1;
p1=input();
n++;
if(n==3)
{
printf("输入次数超过三次!\n");
exit(1);
}

}
int main()
{
char* p;
p=input();
return 0;
}

检查口令是否正确,输入错误三次则退出!
这是一练习题,水平有限,请各位前辈不要笑话!
0 0
原创粉丝点击