#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main(){
int ch;
int rec;
char password[20] = { 0 };
for (int i = 1; i <= 3; i++) {
printf("请输入密码:\n");
scanf("%s", &password);//只读取空格之前的字符
while ((ch = getchar() != '\n')) {
;
}
printf("请确认(Y/N):\n");
rec = getchar();
if (rec == 'Y') {
printf("确认成功\n");
}
else {
printf("确认失败\n");
}
if ((strcmp(password, "123456")) == 0) {
printf("密码正确\n");
break;
}
else {
printf("密码错误");
}
}
return 0;
}
实现功能:
1.三次机会,如果全错误就退出程序
2.密码无论输入多少,只读取空格前的6位数字。
标签:ch,SECURE,CRT,int,char,简单,设计,密码锁 From: https://blog.51cto.com/u_16080683/6251886