#include<stdio.h>
int main(void)
{
char password[] = "12345qwe";
char input[30];
int i, op;
op = 3;
printf("Please input code,you have only 3 times to input a right code\n\a");
for (i = 0; i < 3; i++)
{
scanf_s("%s", &input,30);
if ((strcmp(input,"12345qaz")) == 0)
{
printf("Access in!\n");
break;
}
else
{
op--;
printf("Code error!You have only %d times to input a right code\n\a", op);
}
}
if (op < 1)
{
printf("Time out,Program quit!\n\a");
}
return 0;
}
本文介绍了一个简单的C语言程序,演示了如何通过`scanf_s`接收用户输入的3位密码,仅允许用户在3次尝试内正确输入预设的'12345qaz'才能访问。错误输入会减少剩余尝试次数,超时则程序退出。

1824

被折叠的 条评论
为什么被折叠?



