Difficulty: Easy
Correct Answer: "I am a boy\r\n\0"
Explanation:
Introduction / Context:On Windows, text files commonly use CRLF line endings, represented as carriage return followed by newline (\r). Understanding how fgets handles these characters is key to correctly parsing input and trimming line endings for cross-platform applications.
Given Data / Assumptions:
Concept / Approach:
Step-by-Step Solution:
Input stream bytes → 'I am a boy\r'.fgets copies bytes until and including , so both \r and end up in the buffer.fgets appends \0, yielding 'I am a boy\r\0' in memory.Verification / Alternative check:
Printing with debugging or inspecting byte values shows 0x0D (\r), 0x0A (), followed by 0x00.Why Other Options Are Wrong:
Common Pitfalls:
Final Answer:
"I am a boy\r\0"
Discussion & Comments