Non-blocking getch(), ncurses

The curses library is a package deal. You can’t just pull out one routine and hope for the best without properly initializing the library. Here’s a code that correctly blocks on getch():

#include <curses.h>

int main(void) {
  initscr();
  timeout(-1);
  int c = getch();
  endwin();
  printf ("%d %c\n", c, c);
  return 0;
}

Leave a Comment