Which of the following function is more appropriate for reading in a multi-word string? ans. gets() puts() printf() scanf()
Question
Which of the following function is more appropriate for reading in a multi-word string? ans. gets()
puts()
printf()
scanf()
Solution
The most appropriate function for reading in a multi-word string is gets().
Here's why:
-
gets(): This function is used to read a line from the standard input (keyboard) and store it in an array of type char. It can read multi-word strings as it does not stop reading input on encountering the first white space. -
puts(): This function is used to write a string to the standard output (screen). It is not used for reading strings. -
printf(): This function is used to output a string to the standard output. Likeputs(), it is not used for reading strings. -
scanf(): This function is used to read input from the standard input. However, it stops reading input on encountering the first white space, so it is not suitable for reading multi-word strings.
Therefore, gets() is the most appropriate function for reading in a multi-word string.
Similar Questions
Which of the following function is more appropriate for reading in a multi-word string?ans.puts()scanf()gets()printf() Previous Marked for Review Next
Which of the following function is more appropriate for reading in a multi-word string? ans.
StringsWhich of the given function is more appropriate for reading in a multi-word string including spaces?Optionsscanf()gets()getchar()puts()
Which of the following function is more appropriate for reading in a multi-word string in c?
Which of the following function used as reading data ?Options :main()print()scanf()printf()
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.