密码的简单模拟

 1 #include<stdio.h>
 2 char password[]="592026",intput[10000];
 3 int main()
 4 {
 5     int p();
 6     int i,n=5,t;
 7     char sr;
 8     printf("You have only 5 chances!
");
 9     while(n--)
10     {
11         i=0;
12         printf("Please intput password:");
13         while((sr=getch())!='
')
14         {
15             if(sr=='')
16             {
17                 printf(" ");
18                 intput[--i]='';
19             }
20             else
21             {
22                 intput[i++]=sr;
23                 printf("*");
24             }
25         }
26         printf("
");
27         t=p();
28         if(t)
29             break;
30         printf("
");
31     }
32     if(!t)
33         printf("Input more than 5 times!");
34 }
35 
36 int p()
37 {
38     int i=0,t=0;
39     while(password[i]!='')
40     {
41         if(!i&&intput[i]==password[i])
42             t=1;
43         if(intput[i]!=password[i])
44         {
45             t=0;
46             break;
47         }
48         if(password[i+1]==''&&intput[i+1]!='')
49             t=0;
50         ++i;
51     }
52     if(t)
53         printf("Password is right!
");
54     else
55         printf("Password is error!
");
56     return t;
57 }
原文地址:https://www.cnblogs.com/qq188380780/p/6058495.html