/****************************************************
Function: d_password()
Description: 以星号形式输入密码!
Calls:
Calls By:
Table Accessed:
Table Updates:
Input:
Output:
Return:
Others:
****************************************************/
void d_password(char *str)
{
int i;
char ch;
system("stty -icanon");//关闭缓冲区
system("stty -echo");//关闭回显
//密码长度最长为20位
for(i = 0;i < 20;i++)
{
ch = getchar();
//遇换行符结束输入
if(ch == '\n')
{
break;
}
//遇退格符删除一个字符
if(ch == 127 )
{
if(i <= 0)
{
i--;
}
else
{
printf("\b");
printf(" ");//用空格代替
printf("\b");
i = i - 2;
}
}
else
{
str[i] = ch;
printf("*");//输出*号
}
}
str[i] = '\0';//字符串结束
printf("\n");
system("stty icanon");//打开缓冲区
system("stty echo");//打开回显
}