Difficulty: Easy
Correct Answer: gets()
Explanation:
Introduction / Context:Reading text that contains spaces (for example, full names or sentences) requires care in C. Basic token-oriented input like scanf with the %s specifier stops at whitespace, which truncates multi-word input. Older C textbooks often used gets to read an entire line including spaces. Although gets is now removed from the C standard due to safety issues, understanding why it was historically chosen explains the intended behavior of multi-word input questions and highlights safer modern alternatives.
Given Data / Assumptions:
Concept / Approach:
Step-by-Step Solution:
Identify requirement: accept spaces → single-token readers like scanf("%s") are unsuitable.Eliminate output-only functions (printf, puts) because they do not read input.Select the remaining function that reads a whole line including spaces → gets (historically).Verification / Alternative check:
Practical test: entering 'I am here' → scanf("%s") captures 'I' only; gets would have captured the full line.Why Other Options Are Wrong:
Common Pitfalls:
Final Answer:
gets()
Discussion & Comments