#include <stdio.h>
#include <conio.h>
//2.输入密码功能
void InputPassword(char pw[])//char *pw
{
char ch; //用户输入的密码字符
const char* pold = pw;//保存密码数组的首地址,用于循环内比较
while((ch=getch())!='\r')//ASCII码值为13('\r')回车
{
if(ch=='\b'&&pw > pold)//如果按下的是退格键并且字符数组中有数据,才能进行退格操作
{
printf("\b \b");//\b是向左移动一个位置并没有删除1234
--pw;
continue;//跳过本次循环
}
printf("*");//输入一个字符打印一个*号
*pw = ch;//把获取的字符赋值给pw指针所指向的那块存储区域
++pw; //让指针指向一块存储区域
}
*pw='\0';//加上字符串的结尾标记
}
int main()
{
char my_pw[10]; //用户输入的密码
InputPassword(my_pw);//函数调用
printf("\n\n用户输入的密码是:%s\n",my_pw);
return 0;
}