【找错】模拟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(
相关问答:
写了个测试程序如下
struct hostent *hp;
char AlarmDevIP[20];
int x2;
hp = gethostbyname("www.google.com");
if (hp)
{
......
两个文件1.PC,1.inc
1.PC有操作oracle数据库的 ,1.inc也有操作oracle数据库
在其他数据中如informix 中$include 1.inc就可以使用了
在ORACLE数据库重 $include 1.inc不可用 EXEC SQL include 1.inc也不可 ......
在自己的电脑上安装了ubuntu 就是想玩一下3D桌面,于是下载了
compizconfig-settings-manager
emerald
simple-ccsm
fusion
这些东西,安装完之后,我在电脑里点击了emerald ......
linux 下C编程 集成开发环境 用什么比较好
我初步选定 codeblock
呵呵 还有 在linux 写了一个打印中文的代码,而今天在windows 下查看那个代码 , 是乱码 而后想到先用 EditPlus先进行编辑 然后复制 ......
在LINUX裏安裝 CURL 時,出現如下報錯
checking for SSL support in libcurl... no
checking for curl_easy_perform in -lcurl... no
configure: error: There is something ......