yum install ncurses-devel ncurses
Debian / Ubuntu Linux下的方法:
sudo apt-get install libncurses5-dev libncursesw5-dev
如果不安装库的话,在编译的时候会出现如下的错误:
fatal error: curses.h: No such file or directory
compilation terminated.
compilation terminated.
编写源文件:secert.c
#include<stdio.h>
#include<curses.h>
int main()
{
char p[20];
printf("Please Input password:");
initscr();//该函数是启动curses模式,在此是关闭了终端回显,实现密码效果
scanf("%s",p);
endwin();//该函数是关闭curses模式。在此即恢复终端回显
printf("Your password is:%s\n",p);
return 0;
}
编译:gcc secret.c -o secret -lcurses
执行:./secret
输入密码后,按回车