How to implement getch() function of C in Linux?
问题 In TurboC++, I can use the getch() function from conio.h . But in Linux, gcc doesn\'t provide conio.h . How can I get the functionality of getch() ? 回答1: 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();