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 used as reading data ?Options :main()print()scanf()printf()
Explain different input and output functions in c with example (scanf,printf,gets,puts).
Which of these method of FileReader class is used to read characters from a file?Question 2Answera.read()b.scanf()c.get()d.getInteger()
Which of these method of FileReader class is used to read characters from a file?Optionsscanf()read()get()getInteger()
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.