#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
void InputPass(char pw[])//输入密码,用数组存储
{
char ch;//用户输入密码字符 输入字符\r属于回车的意思
const char* pold=pw;//保存密码数组的首地址,用于循环内的比较
while((ch=getch())!='\r')//循环输入每个字符并判断不等于\r
{
if(ch=='\b'&&pw>pold)//如果按下的是退格键并且字符数组中有数据,我们才进行退格操作
{
printf("\b \b");
--pw;
continue;
}
printf("*");
*pw=ch;//把获取的字符赋给pw指针所指向的那块存储区域
++pw;
}
*pw='\0';//加上字符串结尾标记
}
int main()
{//数组是用来存储一堆相同数据类型的数据
char my_pw[10];//我输入的密码
printf("\n请输入密码:\n");
InputPass(my_pw);
printf("用户输入的密码是:%s\n",my_pw);
return 0;
}