C select() timeout STDIN single char (no ENTER)
问题 I want to be able to use select() to work with entering a single char (no ENTER) from STDIN. So, when a user press a single key, select() should return immediately, not waiting for the user to hit ENTER. int main(void) { fd_set rfds; struct timeval tv; int retval; /* Watch stdin (fd 0) to see when it has input. */ FD_ZERO(&rfds); FD_SET(0, &rfds); /* Wait up to 2 seconds. */ tv.tv_sec = 2; tv.tv_usec = 0; retval = select(1, &rfds, NULL, NULL, &tv); if (retval == -1) perror("select()"); else