$sudo gedit
把虚线框里面的内容粘贴进文档文本里面
----------------------------------------------------------------------------------------------------------
#include <termios.h>
#include <stdio.h>
static struct termios old, new;
/* Initialize new terminal i/o settings */
void initTermios(int echo)
{
tcgetattr(0, &old); /* grab old terminal i/o settings */
new = old; /* make new settings same as old settings */
new.c_lflag &= ~ICANON; /* disable buffered i/o */
new.c_lflag &= echo ? ECHO : ~ECHO; /* set echo mode */
tcsetattr(0, TCSANOW, &new); /* use these new terminal i/o settings now */
}
/* Restore old terminal i/o settings */
void resetTermios(void)
{
tcsetattr(0, TCSANOW, &old);
}
/* Read 1 character - echo defines echo mode */
char getch_(int echo)
{
char ch;
initTermios(echo);
ch = getchar();
resetTermios();
return ch;
}
/* Read 1 character without echo */
char getch(void)
{
return getch_(0);
}
/* Read 1 character with echo */
char getche(void)
{
return getch_(1);
}
/* Let's test it out */
----------------------------------------------------------------------------------------------------
另存为到 /usr/include/conio.h
下面也有现成的文件,可自己下载放进该目录下
Ubuntu 13.04 codeblocks下编译通过
可自由转载,转载请注明出处,谢谢
本文介绍了一个在 Linux 环境下实现类似 Windows 中 getch 函数的方法。通过使用 termios.h 中的函数,可以实现在不回显的情况下读取键盘输入。代码已在 Ubuntu 13.04 的 CodeBlocks 中验证通过。
6086

被折叠的 条评论
为什么被折叠?



