搜索
查看: 2702|回复: 3
打印 上一主题 下一主题

关于输入字符回显星号的问题,求助!

[复制链接]
楼主
发表于 2012-12-5 12:31:11 | 显示全部楼层
看看这个
{:soso_e100:}
1#define TRUE 1
2#define FALSE 0
3#define MIN_INPUT 0x20
4#define MAX_INPUT 0x7e
5/*
6* 所有功能有此函数实现:
7* pszPw : 保存密码的缓冲
8* iMaxSize :最大的密码长度,该长度必须小于缓冲区大小。
9* 返回值为TRUE为成功获取密码。总是返回TRUE
10*/
11int GetPassword(unsigned char* pszPw,int iMaxSize)
12{
13unsigned char ch;
14int i=0;
15
16int bIsEcho=TRUE;
17//while( ! kbhit() && i<iMaxSize )
18while( ( ch = (unsigned char)getch() ) && i < iMaxSize )
19{
20//ch = (unsigned char)getch();
21bIsEcho=TRUE;
22
23if ( ch == 13)
24{
25pszPw[i++]=0;
26break;
27}
28else if ( ch >= MIN_INPUT && ch <= MAX_INPUT) /*所有可打印字符*/
29{
30pszPw[i++]=ch;
31}
32else if ( ch == 8 && i> 0 ) /*退格键*/
33{
34pszPw[i--] = 0;
35bIsEcho = FALSE;
36putchar( ch );
37putchar( ' ' );
38putchar( ch );
39
40}
41else
42bIsEcho = FALSE;
43
44if(bIsEcho)
45putchar('*');
46
47}
48
49pszPw=0;
50return TRUE;
51}
52
53int main(void)
54{
55int iMaxSize=80;
56unsigned char pw[99];
57if ( GetPassword(pw,iMaxSize) == TRUE ){
58printf("\npassword=%s",pw);
59}
60else{
61printf("\nCan not get the password!");
62}
63}









QQ拼音截图未命名.png (33.63 KB, 下载次数: 1)

QQ拼音截图未命名.png

201212081737.2.zip

5.42 KB, 下载次数: 10

你要你东西

沙发
发表于 2012-12-8 17:42:39 | 显示全部楼层
main()
{
后加我的
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

广播台
特别关注
快速回复 返回顶部 返回列表