I need my program written in pure C to stop execution when stdin is closed.
There is indefinite work done in program main cycle, and there is no way I can use ...
I’m writing a small C program that must accept an input stream larger than 4096 bytes.
I did find a post that recommended using setvbuf() here:
Making fgets issue longer read() calls ...
#include #include #include #include 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 five seconds. */ tv.tv_sec = 5; tv.tv_usec = 0; retval = select(1, &rfds, NULL, NULL, &tv); /* Don't rely on the value of tv ...