...
After the loop ends, if feof(stdin) != 0
, the loop has read through to the end of the file without encountering a newline character. Similarly, if ferror(stdin) != 0
, a read error occurred before the loop encountered a newline character, and if chars_read > index
, the input string has been truncated. void FIO34-C. Use int to capture the return value of character IO functions that might be used to check for end of fileDo not compare characters from a file with EOF is also applied in this solution.
...
Code Block |
---|
while (((ch = getchar()) != '\n') && ch != EOF) |
...
feof(stdin) |
...
&& !ferror(stdin)) |
Noncompliant Code Example (scanf()
)
...
...