题目:请编写一个输入密码(不回显)的程序,要求通过设置终端来完成。
完成代码:
#include <stdio.h> #include <unistd.h> #include <termio.h> int main() { struct termio new, old; ioctl(STDIN_FILENO, TCGETA, &old); new = old; new.c_lflag &= (~ECHO); ioctl(STDIN_FILENO, TCSETA, &new); printf("Please input password:"); char szPass[20]; scanf("%s", szPass); printf(" Your password is %s ", szPass); ioctl(STDIN_FILENO, TCSETA, &old); return 0; }