#include
#include
#include
#define PASSWORD_LEN 12
int main(){
struct termios initialrsettings, newrsettings;
char password[PASSWORD_LEN + 1];
tcgetattr(fileno(stdin),&initialrsettings); #获取termios结构并保存
newrsettings = initialrsettings;
newrsettings.c_lflag &= ~ECHO; #清除变量c_lflag中由ECHO定义的比特
printf("Please Enter Password:");
if( tcsetattr(fileno(stdin),TCSAFLUSH,&newrsettings) != 0 ){
fprintf(stderr,"Could not set arrributes\n");
}else{
fgets(password,PASSWORD_LEN,stdin);
tcsetattr(fileno(stdin),TCSANOW,&initialrsettings); #还原之前的termios结构
fprintf(stdout,"\nYou entered %s as the password\n",password);
}
exit(0);
}
|