
...
This compliant solution uses feof()
and ferror()
to test for whether the EOF
was an actual character or a real EOF
because of end-of-file and ferror()
to test for or errors:
Code Block | ||||
---|---|---|---|---|
| ||||
#include <stdio.h> void func(void) { int c; do { c = getchar(); } while (c != EOF); if || (!feof(stdin)) { /* Handle end of file */ } else if (&& !ferror(stdin)) { /* Handle file error */ } else { /* Received a character that resembles EOF; handle error */ }))); } |
Noncompliant Code Example (Nonportable)
...