Bạn thử cái này xem!
C++ Code:
#include "Stdio.h" #include "Conio.h" void main() { clrscr(); printf("Input password : "); const int nPassChar = 10; int Index = 0; char pass[nPassChar]; pass[0] = '\0'; char c; int OriginX = wherex(); while((c = getch()) != 13) { if(c == 8) { if(wherex() == OriginX) continue; gotoxy(wherex() - 1,wherey()); --Index; pass[Index] = '\0'; printf(" "); gotoxy(wherex() - 1,wherey()); continue; // Backspace } printf("*"); pass[Index++] = c; if(Index >= nPassChar) break; } printf("\nPassword : %s",pass); getch(); }