第2个回答 2018-01-04
//输入用户名
int login()
{
char tmpname[20],tmppwd[20];
char c;
int i=0,j;
while(i<3)
{
system("cls");
printf("请输入用户名:\n");
scanf("%s",tmpname);
printf("请输入密码:\n");
j=0;
while(1)//循环读单个字符
{
c=getch();
if(c=='\r')
{
tmppwd[j]=0;
break;
}
printf("*");
tmppwd[j]=c;
j++;
}
if(strcmp(tmpname,name)==0 && strcmp(tmppwd,pwd)==0)
return 1;
else
{
i++;
printf("用户名或者密码错误!还有%d次机会。\n",3-i);
system("pause");
if(i==3)
return 0;
}
}
}