linux c 关闭回显

来源:互联网 发布:淘宝怎么看权重 编辑:程序博客网 时间:2024/06/17 12:14
// 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 offscanf("%d",&passwd);set_disp_mode(STDIN_FILENO,1); //echo onprintf("your enter%d\n",passwd);return 0;}


	
				
		
原创粉丝点击