LearnFrenzy
Sign in Take a free test

C Input / Output · Input/Output MCQ · Question 4

What does fgets() do with the newline? Answer, explanation & discussion

  • MCQ
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links