Question 12
Back to Exercise
Is fflush(stdin) a portable way to discard pending input?
- A Yes, it clears the input buffer everywhere
- B No – fflush is defined only for output (or update) streams; on input streams the behaviour is undefined Correct
- C Yes, but only on Linux
- D No, it closes stdin
Correct Answer: Option B
Some libraries allow it as an extension, but standard C does not. Portable code reads and discards: while ((c = getchar()) != '\n' && c != EOF) {}.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!