Date:2012-10-18
原问题:
Write a C program to display * for each letter of password you type in command line. Like:Password ********
我给出的解决方案:
#include <curses.h> int main() { initscr(); char c; noecho(); while((c = getch()) != '\n') { printw("*"); } endwin(); return 0; }
另外linux 下有专门的函数, 屏蔽回显, 但是不会显示星号
#include <stdio.h> #include <unistd.h> int main() { char *passwd = getpass("password:"); printf("%s\n", passwd); return 0; }