社区
Linux/Unix社区
帖子详情
如何让输入字符不回显(不使用curses库)
天蛾糊
2009-10-29 01:01:12
我在做密码输入的程序,用curses库已经实现了,但我觉得不方便,想请教各位高手来指点,谢谢
比如输入一个字符显示一个*直到'\n'为止
...全文
140
1
打赏
收藏
如何让输入字符不回显(不使用curses库)
我在做密码输入的程序,用curses库已经实现了,但我觉得不方便,想请教各位高手来指点,谢谢 比如输入一个字符显示一个*直到'\n'为止
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
1 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
winter_sui
2009-10-29
打赏
举报
回复
网上搜索的:
#include <stdio.h>
#ifndef _WIN32 //Linux platform
#include <termio.h>
#ifndef STDIN_FILENO
#define STDIN_FILENO 0
#endif
int getch(void)
{
struct termios tm, tm_old;
int fd = STDIN_FILENO, c;
if(tcgetattr(fd, &tm) < 0)
return -1;
tm_old = tm;
cfmakeraw(&tm);
if(tcsetattr(fd, TCSANOW, &tm) < 0)
return -1;
c = fgetc(stdin);
if(tcsetattr(fd, TCSANOW, &tm_old) < 0)
return -1;
return c;
}
#else //WIN32 platform
#include <conio.h>
#endif
#define MAX_LEN 8
#define BACKSPACE 8
#define ENTER 13
#define ALARM 7
char *getPasswd(const char *prompt)
{
int i=0, ch;
static char p[MAX_LEN+1]="";
printf("%s", prompt);
while((ch = getch())!= -1 && ch != ENTER)
{
if(i == MAX_LEN && ch != BACKSPACE)
{
putchar(ALARM);
continue;
}
if(ch == BACKSPACE)
{
if(i==0)
{
putchar(ALARM);
continue;
}
i--;
putchar(BACKSPACE);
putchar(' ');
putchar(BACKSPACE);
}
else
{
p[i] = ch;
putchar('*');
i++;
}
}
if(ch == -1)
{
while(i != -1)
{
p[i--] = '\0';
}
return NULL;
}
p[i]='\0';
printf("\n");
return p;
}
int main()
{
char *pw = getPasswd("passwd:");
puts(pw);
puts("clearing the static buffer with 0 ...");
while(*pw)
{
*pw++=0;
}
pw=NULL;
return 0;
}
Note-Station-to-markdown
这是一个跨平台脚本,可将 Synology Note Station 的笔记转换为 Markdown 文件。脚本
使用
Python 编写,可在任何桌面平台上运行。 转换后您将获得: 1、以导出的笔记本命名的文件夹; 2、这些文件夹中以所有内联图片原位存储的 Markdown 语法纯文本文件笔记; 3、在笔记文本开头处分配标签和附件链接; 4、所有图片和附加文件都位于笔记本目录下的媒体子目录中。
区县-专精特新企业数量(2013-2025年).xlsx
详细介绍及样例数据:https://blog.csdn.net/li514006030/article/details/162965929
Linux/Unix社区
23,223
社区成员
74,536
社区内容
发帖
与我相关
我的任务
Linux/Unix社区
Linux/Unix社区 应用程序开发区
复制链接
扫一扫
分享
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章