终端程序getchar改为getch
来源:互联网 发布:nodejs mysql github 编辑:程序博客网 时间:2024/06/05 00:25
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#define ESC_KEY 0x1b
char table[255];
static int getch();
int main(int argc, char **argv)
{
int ch;
unsigned int length=0;
memset(table,'\0',255);
printf("\r\n->");
while( 1 )
{
//printf( "\r\nch_c=%c ,ch_x=%02x",ch,ch);
ch = getch();
if(ch == 0x08)
{
if(length > 0)
{
length--;
printf("%c",ch);
printf("%c",table[length] = 0x20);
printf("%c",ch);
printf("%c",table[length] = '\0');
}
}
else
{
printf("%c",table[length] = ch);
length++;
}
}
return 0;
}
static int getch(void)
{
struct termios oldt,newt;
int ch;
if (!isatty(STDIN_FILENO)) {
fprintf(stderr, "this problem should be run at a terminal\n");
exit(1);
}
// save terminal setting
if(tcgetattr(STDIN_FILENO, &oldt) < 0) {
perror("save the terminal setting");
exit(1);
}
// set terminal as need
newt = oldt;
newt.c_lflag &= ~( ICANON | ECHO );
if(tcsetattr(STDIN_FILENO,TCSANOW, &newt) < 0) {
perror("set terminal");
exit(1);
}
ch = getchar();
// restore termial setting
if(tcsetattr(STDIN_FILENO,TCSANOW,&oldt) < 0) {
perror("restore the termial setting");
exit(1);
}
return ch;
}
- 终端程序getchar改为getch
- getch() getchar()
- getchar() getch()
- getchar、getch、getche小记
- getch, getche, getchar区别
- getchar与getch
- getch, getche, getchar区别
- getch() getche()getchar()
- getchar(),getch()和getche()
- getchar() getche() getch() 小结
- getch(),getche()与getchar()
- getchar , getch应用细节
- getch()和getche() getchar()
- getch()和getchar()
- getc,getchar,getch,getche
- getchar() 和 getch()
- getchar()、getch()、getche()
- getch() getche() getchar()
- 开发PHP网站需要掌握的10个技巧
- poj 1679 求最小生成树的值是否唯一
- 3DSMax8.0SDK在VS2005下运行
- 创建一个COM组件
- C/C++拾遗录--关于位域的一些总结
- 终端程序getchar改为getch
- 如何保证两台电脑可以互相访问?
- MSSQL判断字段是否包含中文汉字
- 项目开发与管理| 标签:|字号大中小 订阅
- Discuz! 7.2 二次开发基础 (二)
- Discuz! 7.2 二次开发基础 (一)
- 不眠的夜
- 空降兵如何融入到团队中去
- 几种C/C++语言安全检测工具介绍