Question 4
Back to Exercise
When the line fits in the buffer, what does fgets() do with the newline character?
- A Discards it
- B Keeps it in the buffer, followed by '\0' Correct
- C Replaces it with a space
- D Leaves it in the input stream
Correct Answer: Option B
fgets stores the newline, which also tells you a complete line was read. Remove it with buf[strcspn(buf, "\n")] = '\0';.
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!