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 used as reading data ?Options :main()print()scanf()printf()
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()
you can read a single word at a time from a file usingSelect one:a.fgetc functionb.fscanf functionc.Both A and Bd.None of above
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.