密码回显为*字符,按退格键可以对输入进行修改。
#include <stdio.h>#include <conio.h>#include <windows.h>int main(){char p[20];char *password="1234";int i=0;printf("enter your password(请输入密码)\n");do{p[i]=getch();if(p[i]=='\r')break;if(p[i]=='\b'){if(i==0){printf("\a");continue;}i=i-1;printf("\b");}else{i=i+1;printf("*");}}while(p[i]!='\n' && i<20);p[i]='\0';printf("\n正确密码:%s;输入密码:%s\n",password,p);if(strcmp(p,password)==0)printf("right!\n");elseprintf("error!\n");system("pause");return 0;}