hongdongyu 发表于 2012-8-13 11:20

Linux下getch()使用的问题

#include <stdio.h>
#include <curses.h>
int main(void)
{
char ch;
printf("Input a key:");
initscr();
ch = getch();
endwin();
printf("you put a %c \n",ch);
return 0;
}

linux下为什么第一个printf不会输出,程序运行之后,我输入一个按键(比如:K),然后输出you put a K。
Input a key:------>这一行没有输出啊?

shell.albert 发表于 2012-8-13 20:43

你写的这个程序是顺序执行的,程序输出you put a K后,再一句就是return 0程序都退出了。怎么可能输出呢?
你需要的循环结构!
用while或for吧。
页: [1]
查看完整版本: Linux下getch()使用的问题