标题: 编程开发版精华FAQ
flag
版主
Rank: 7Rank: 7Rank: 7
版主



UID 19801
精华 1
积分 25(积分有什么用?)
帖子 5578
阅读权限 100
注册 2002-7-19
状态 离线
发表于 2005-6-28 08:44  资料  个人空间  短消息  加为好友 

Linux爱好者的盛会
做linux下的程序,如何在从标准输入读密码时关闭回显?
]        QDIS3J6\|使用getpass函数MatFUU6x/zaf
或者:

#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", passwd);
return 1;
}






上帝说,有问题,找GOOGLE 写程序是很神圣的事情!同样只是装系统,卖菜的大娘会的事情不见得就跟卖菜一样了。
顶部
 



当前时区 GMT+8, 现在时间是 2008-5-11 04:34

    Powered by Discuz! 5.5.0  © 2001-2007 Comsenz Inc.
Processed in 0.087789 second(s), 5 queries

清除 Cookies - 联系我们 - Linux伊甸园 - Archiver - WAP