Which of the following function is more appropriate for reading in a multi-word string? gets() puts() scanf() printf()
Question
Which of the following function is more appropriate for reading in a multi-word string? gets()
puts()
scanf()
printf()
Solution
The most appropriate function for reading in a multi-word string is gets().
Here's why:
-
gets()function: This function is used to read a line from the standard input (keyboard) until a newline character or the end of the file. It can read multi-word strings because it does not stop reading input after encountering a space. -
puts()function: This function is used to write a string to the standard output (screen). It's not used for reading strings. -
scanf()function: This function is used to read formatted input from the standard input. However, it stops reading input as soon as it encounters a space, so it's not suitable for reading multi-word strings. -
printf()function: This function is used to write formatted output to the standard output. Likeputs(), it's not used for reading strings.
So, 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
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?
Which of the following function is more appropriate for reading in a multi-word string in c?
function is more appropriate for reading in a multi-word string?ans.
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.