c语言中用户输入的密码用*号代替,可回删

时间:2021-06-16 08:49:17


#include<stdio.h>
#include<string.h>
#include<conio.h>

void main()
{
//char name代表用户名 mm代表登陆密码 a代表输入的密码
char name[20], mm[3]={'y','a','n'},a[6];
int i,g;

printf("\n\n\n\t\t\tStudent Manager");
for(i=0;i<3;i++)
{
printf("\n\n\t\tUser Name:");
scanf("%s",&name);

if(strcmp(name,"grace")==0)
{
printf("\t\tPlease input your password:");
for(g=0;g<6;g++)
{
a[g] = getch(); /*逐次赋值,但不回显*/
if (a[g] == '\x0d')/*回车则终止循环*/
{
a[g]='\0';
break;
}
printf("*"); /*以星号代替字符个数*/
}
break;
}
else
{
printf("\t\tThe wrong user");

}
}
}