'C- nonblocking read of all stdin
I am seeking some non-blocking function (will return any available input but will not wait for more input from the user) which will read any and all stdin data up to n into a buffer and return how many bytes were read.
int n_bytes = readn(&buff, length);
if (n_bytes > 0) {
...
My current attempt uses getchar() until EOF, but that waits for input. I would like to avoid multithreading if possible.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
