Which of the following function is more appropriate for reading in a multi-word string? ans. scanf() printf() gets() puts()
Question
Which of the following function is more appropriate for reading in a multi-word string? ans. scanf()
printf()
gets()
puts()
Solution
The most appropriate function for reading in a multi-word string in C is gets().
Here's why:
-
scanf(): This function reads the input from the user until it encounters a whitespace. So, it's not suitable for multi-word strings. -
printf(): This function is used to print the output, not to read the input. -
gets(): This function reads a line from stdin into the buffer pointed to by s until either a terminating newline or EOF. So, it's suitable for multi-word strings. -
puts(): This function is used to write a string to stdout up to but not including the null character. So, it's not used to read the input.
So, the answer is gets().
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.