// forTest.cpp : Defines the entry point for the console application. #include <stdio.h> #include <termios.h> #include <unistd.h> #include <errno.h> #define ECHOFLAGS (ECHO | ECHOE | ECHOK | ECHONL) //函数set_disp_mode用于控制是否开启输入回显功能 //如果option为0,则关闭回显,为1则打开回显 int set_disp_mode(int fd,int option) { int err; struct termios term; if(tcgetattr(fd,&term)==-1){ perror("Cannot get the attribution of the terminal"); return 1; } if(option) term.c_lflag|=ECHOFLAGS; else term.c_lflag &=~ECHOFLAGS; err=tcsetattr(fd,TCSAFLUSH,&term); if(err==-1 && err==EINTR){ perror("Cannot set the attribution of the terminal"); return 1; } return 0; } int main()//test { int passwd; puts("enter your passwd"); set_disp_mode(STDIN_FILENO,0); //echo off scanf("%d",&passwd); set_disp_mode(STDIN_FILENO,1); //echo on printf("your enter%d\n",passwd); return 0; }
linux c 关闭回显
最新推荐文章于 2024-07-27 11:04:27 发布