#include<stdio.h>
#include<conio.h>
extern int F();
extern int G();
extern int H(char x, char y);
//extern char A[];
//extern int B[];
//extern int C[];
char A[12] = {0}; // MODIFY BY n0noper NOTE:这里你只给了这一个文件,我们没法用,方便调试所以改了
char B[12] = {0};
char C[12] = {0};
int main()
{
Doop: int a, b;
printf("请选择(相应的数字);\n");
printf("1.设定密码;\n");
printf("2.验证密码;\n");
scanf_s("%d", &a);
if (a == 1)
{
Loop: b = F();
if (b == 1) // MODIFY BY n0noper NOTE: Loop标识上移
{
printf("两次输入不同;请重新输入;");
goto Loop;
}
printf("设定成功;\n");
}
else if (a == 2)
{
Soop: b = G();
if (b == 1)
{
printf("输入错误;请重新输入;");
goto Soop;
}
printf("输入正确");
}
else
{
printf("选择错误请重新选择;");
goto Doop;
}
}
int F()
{
printf("请设定密码:\n");
fflush(stdin); // ADD BY n0noper NOTE: 清除输入缓存,防止上次输入结果的影响
int i,o;
for (i = 0; i < 11; i++)//第一次输入密码
{
A[i] = (char)getch(); // scanf_s("%c", &A[i]);//获取字符 // MODIFY BY n0noper NOTE:&A[i] -> A[i]
if (13 == A[i]) break; // if (A[i] = 13) break; //输入回车键跳出循环 // MODIFY BY n0noper NOTE:下次注意!
printf("*");
}
printf("请再次输入密码:\n");
fflush(stdin); // ADD BY n0noper NOTE: 清除输入缓存,防止上次输入结果的影响
for (i = 0; i < 11; i++)//再次输入密码
{
B[i] = (char)getch(); // scanf_s("%c",&B[i]);//获取字符 // MODIFY BY n0noper NOTE:scanf不会自动停止
if (13 == B[i]) break; // if (B[i] = 13) break;//输入回车键跳出循环 // MODIFY BY n0noper NOTE:下次注意!
printf("*");
}
for (i = 0; i < 11; i++)
{
o = H(A[i], B[i]);//判断两次输入是否相等;
if(o == 1) return 1;//不相等时的返回值;
}
return 0;
}
int G()
{
printf("请输入密码:");
fflush(stdin); // ADD BY n0noper NOTE: 清除输入缓存,防止上次输入结果的影响
int i,o;
for (i = 0; i < 11; i++)//
{
C[i] = (char)getch(); // scanf_s("%c", &C[i]);//获取字符 // MODIFY BY n0noper
if (C[i] = 13) break;//输入回车键跳出循环
printf("*");
}
for (i = 0; i < 11; i++)
{
o = H(A[i], C[i]);
if (o == 1) return 1;
}
return 0;
}
int H(char x,char y)
{
int i;
// for (i = 0; i < 11; i++) // NOTE:这个循环不要闹
{
if (x != y) return 1;
}
return 0;
}
// 有什么问题,再讨论。
|