日期:2014-05-16  浏览次数:20779 次

Linux下用c语言编写输入密码程序
怎么在linux下用c编写个输入密码的程序,而且是不能回显密码的那种程序!!!求指点啊!!!

------解决方案--------------------
getpass(3)
------解决方案--------------------
记得在windows下getch();
在linux你可以写一个类似
#include<iostream>
#include<termios.h>
#include<stdio.h>
namespace getch_name{
char getch(void)
{
char buf = 0;
struct termios old = {0};
if (tcgetattr(0, &old) < 0)
perror("tcsetattr()");
old.c_lflag &= ~ICANON;
old.c_lflag &= ~ECHO;
old.c_cc[VMIN] = 1;
old.c_cc[VTIME] = 0;
if (tcsetattr(0, TCSANOW, &old) < 0)
perror("tcsetattr ICANON");
if (read(0, &buf, 1) < 0)
perror ("read()");
old.c_lflag |= ICANON;
old.c_lflag |= ECHO;
if (tcsetattr(0, TCSADRAIN, &old) < 0)
perror ("tcsetattr ~ICANON");
return (buf);
}
}//命名空间到结束
------解决方案--------------------
去找找设置终端的函数。