I wish to read input from standard input until EOF is detected:
Specifically, I want the input to immediately terminate on EOF, instead of the following:Code:#include <stdio.h> #define MAX 127 int main() { char str[MAX+1]; int c, i = 0; while (i < MAX && (c=getchar()) != EOF) str[i++]=c; str[i] = '\0'; printf("EOF detected\n"); return 0; }
It should be:testing^D
testing^D
EOF detected
insteadtestingEOF detected