易截截图软件、单文件、免安装、纯绿色、仅160KB

【找错】模拟linux登录时记录用户名和密码

这段代码在linux下运行,用于读取输入的用户名和密码,但是在输入过程中,还会接收诸如 上下左右方向键以及其他F1,F2,PAGEUP,PAGEDOWN等键,请问怎么把这些屏蔽啊?就是做成linux系统登录时候那种样子,禁止字符以外的输入字符啊?
C/C++ code:

#include <stdio.h>
#include <sys/types.h>
#ifndef _WIN32 //Linux platform
#include <termio.h>
#ifndef STDIN_FILENO
#define STDIN_FILENO 0
#endif

#else //WIN32 platform
#include <conio.h>
#endif

#define MAX_LEN 256
#define BACKSPACE 127
#define ENTER 13
#define ALARM 7

int my_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;
}
char *getPasswd(const char *prompt)
{
int i=0, ch;
static char p[MAX_LEN+1]="";
printf("%s", prompt);
while((ch = my_getch())!= -1 && ch != ENTER)
{
if(i == MAX_LEN && ch != BACKSPACE)
{
putchar(ALARM);
continue;
}
if(


相关问答:

linux环境下gethostbyname函数问题 - C/C++ / C语言

写了个测试程序如下
   
  struct hostent *hp; 
char AlarmDevIP[20];  
  int x2;

hp = gethostbyname("www.google.com");
if (hp)
{ ......

linux下C语言开发oracle的问题。

两个文件1.PC,1.inc
1.PC有操作oracle数据库的 ,1.inc也有操作oracle数据库 
在其他数据中如informix 中$include 1.inc就可以使用了
在ORACLE数据库重 $include 1.inc不可用 EXEC SQL include 1.inc也不可 ......

linux桌面进不去了,怎么办………………

在自己的电脑上安装了ubuntu 就是想玩一下3D桌面,于是下载了 
compizconfig-settings-manager 
emerald 
simple-ccsm 
fusion 
这些东西,安装完之后,我在电脑里点击了emerald ......

linux 下C编程工具问题 请教 - C/C++ / C语言

linux 下C编程 集成开发环境 用什么比较好 
我初步选定 codeblock 
呵呵 还有 在linux 写了一个打印中文的代码,而今天在windows 下查看那个代码 , 是乱码 而后想到先用 EditPlus先进行编辑 然后复制 ......

請教 LINUX 安裝 PHP5 - PHP / 基础编程

在LINUX裏安裝 CURL 時,出現如下報錯
checking for SSL support in libcurl... no
checking for curl_easy_perform in -lcurl... no
configure: error: There is something ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号