Difficulty: Medium
Correct Answer: agpu
Explanation:
Introduction / Context:
This problem checks understanding of byte-wise seeking and bounded line input. fseek moves the file position indicator, and fgets reads a limited number of bytes into a buffer, appending a null terminator.
Given Data / Assumptions:
Concept / Approach:
Starting at index 9 ('a'), reading 4 characters yields 'a', 'g', 'p', 'u'. fgets writes those and appends '\0', so the buffer contains "agpu".
Step-by-Step Solution:
Seek to index 9 → current char = 'a'.Read 4 chars with fgets → 'a', 'g', 'p', 'u'.Buffer becomes "agpu" → puts prints "agpu" plus a newline.
Verification / Alternative check:
Changing the second argument of fgets to 6 would read 5 characters → "agpur".
Why Other Options Are Wrong:
"Nagp" would require starting at 'N' (index 8). "gpur" starts at index 10, not 9. "agpur" reads 5 letters, exceeding the given size.
Common Pitfalls:
Forgetting that fgets counts the terminator in its size and stops after size-1 characters.
Final Answer:
agpu
Discussion & Comments