/*星号密码输入功能*/
#include
#include
#define MAXLEN 13 /*密码最大长度为12(13-1)*/
int main()
{
char password[MAXLEN];
char c;
int i=0;
puts("请输入密码:");
while(i
c=getch(); /*接收字符不回显*/
switch (c)
{
case 8: /*BackSpace键*/
/*用一个空格替换原字符并把光标后移一位*/
if (i!=0){
--i;
password[i]='\0';
putchar('\b');
putchar(' ');
putchar('\b');
break;
}
break; /*当i为0时退出*/
case '\r': /*回车键*/
goto dispkey;
default:
password[i]=c;
putchar('*');
++i;
}
}
dispkey:
password[i]='\0';
printf("\n你的密码是:\n%s",password);
getch();
return 0;
}