I want to use select() to work with typing a single char (no ENTER) from STDIN.
So, when the user presses one key, select() should immediately return, without waiting for the user to press ENTER.
int main(void) { fd_set rfds; struct timeval tv; int retval; FD_ZERO(&rfds); FD_SET(0, &rfds); tv.tv_sec = 2; tv.tv_usec = 0; retval = select(1, &rfds, NULL, NULL, &tv); if (retval == -1) perror("select()"); else if (retval) printf("Data is available now.\n"); else printf("No data within five seconds.\n"); exit(EXIT_SUCCESS); }
This works, but you need to press the ENTER key to finish. I just want the selection to not wait for the user to press the key and ENTER.
Thanks.
source share