现在的位置: 首页 > 综合 > 正文

linux stdio 关闭回显

2019年06月01日 ⁄ 综合 ⁄ 共 426字 ⁄ 字号 评论关闭
#include   <stdlib.h> 
#include   <stdio.h> 
#include   <string.h> 
#include   <errno.h> 
#include   <unistd.h> 
#include   <termio.h> 

int   getPasswd(char   *passwd) 
{ 
                struct   termio   tbuf_old,tbuf; 

                ioctl(0,   TCGETA,   &tbuf_old); 
                ioctl(0,   TCGETA,   &tbuf); 
                tbuf.c_lflag   &=~ECHO; 
                if   (ioctl(0,   TCSETAF,   &tbuf)   !=   0) 
          return; 
                
                printf( "please   input   passwd: "); 
                scanf( "%s ",   passwd); 
                ioctl(0,   TCSETAF,   &tbuf_old); 
                return   0; 
}; 

int   main() 
{ 
char   passwd[8]; 

getPasswd(   passwd   ); 

printf( "pass:   %s\n ",   passwd); 

return   1; 
} 

 

抱歉!评论已关闭.