【发布时间】:2017-07-31 10:47:38
【问题描述】:
我在 Linux mint 中安装了 ncurses 库,但我仍然无法在 c 中使用 getch 函数。我正在使用 Linux mint 18.2。
这是我的程序:
#include <stdio.h>
#include <curses.h>
int main() {
char k;
printf("how are you");
k = getch();
printf("%c",k);
}
这是输出:
ram@ram$ gcc-7 test.c -lcurses
ram@ram$ ./a.out
how are you�ram@ram$
它不会等待我按下任何键并快速终止。我不想为 Linux 安装 conio.h。如何在 Linux 中使用 getch 和 getche 函数?请不要告诉我做我自己的功能。我还是菜鸟。或者必须有替代品。
【问题讨论】:
-
getch()仅在初始化 curses 后定义了行为。谷歌至少initscr()和endwin()。 -
顺便说一句,您不能将
stdio函数与curses函数混合使用。 -
更重要的是:为什么?你想达到什么目的?从当前的问题陈述来看,您似乎不需要任何 ncurses。那么?
-
也许你想改用
getchar()?