要求输入的密码用***显示……
要求输入的密码用***显示……麻烦高手帮忙一下!
#include<stdio.h> #include<stdlib.h> #include<conio.h> #define MAX 100 #define BACKSPACE 8 int main(void) { char passwords[MAX+1], ch; int i=0; puts("Input the passwords:"); while((ch = getch()) != '\r' && i < MAX) { if (ch == BACKSPACE) { if (i > 0) { passwords[--i] = NULL; printf("\b "); printf("%c%c%c", BACKSPACE, ' ', BACKSPACE); } else putchar(7); //bell } else { passwords[i++] = ch; printf("*"); } } passwords[i] = '\0'; printf("\nYour passwords is: "); puts(passwords); system("pause"); return 0; }