How to implement getch() function of C in Linux?

Try this conio.h file: #include <termios.h> #include <unistd.h> #include <stdio.h> /* reads from keypress, doesn’t echo */ int getch(void) { struct termios oldattr, newattr; int ch; tcgetattr( STDIN_FILENO, &oldattr ); newattr = oldattr; newattr.c_lflag &= ~( ICANON | ECHO ); tcsetattr( STDIN_FILENO, TCSANOW, &newattr ); ch = getchar(); tcsetattr( STDIN_FILENO, TCSANOW, &oldattr ); return ch; … Read more

Using kbhit() and getch() on Linux

If your linux has no conio.h that supports kbhit() you can look here for Morgan Mattews’s code to provide kbhit() functionality in a way compatible with any POSIX compliant system. As the trick desactivate buffering at termios level, it should also solve the getchar() issue as demonstrated here.