getch 函数 当ubuntu下没有curses.h下怎么办?

getch
功 能
  在windows平台下从控制台无回显地取一个字符,在linux下是有回显的。
用 法
  int getch(void);
  在linux平台下时(即包含的是curses.h),还应该在使用函数之前使用initscr(),使用完毕之后调用endwin().否则的话不需输入就会返回。

  #include <stdio.h>
  #include <curses.h> //linux 下
  #include <conio.h> //window 平台
  int main(void)
  {
  char ch;
  initscr();//linux 下
  printf("Input a character:");
  ch = getch();
  printf("\nYou input a '%c'\n", ch);
  endwin();//linux 下
  return 0;
  }

在WINDOWS/MS-DOS中,也可以利用getch()函数让程序调试运行结束后等待编程者按下键盘才返回编辑界面,用法:包含conio.h头文件后,在主函数结尾,return 0;之前加上getch();即可
  这个函数可以让用户按下任意键而不需要回车就可以接受到用户的输入。可以用来作为“press any key to continue”的实现。

############################
当ubuntu下没有curses.h下怎么办?
安装上 libncurses5-dev
然后编译的时候加上 -lncurses
sudo apt-get install libncurses5-dev
gcc -Wall -lncurses -o "test" "test.c"

http://www.pythonschool.com/python/9.html 转摘

原文地址:https://www.cnblogs.com/pythonschool/p/2729287.html