[Solved] How to add a timeout when reading from `stdin` [closed]
The following program will read from stdin with a timeout, which is what you want. #include <stdio.h> #include <unistd.h> #include <sys/select.h> #define LEN 100 int main() { struct timeval timeout = {3, 0}; fd_set fds; FD_ZERO(&fds); FD_SET(STDIN_FILENO, &fds); printf(“Hi. What is your name?\n”); int ret = select(1, &fds, NULL, NULL, &timeout); if (ret == -1) … Read more