+ 18
What is the difference between gets() and scanf() in c
What is the difference between gets() and scanf() in c
4 Antworten
+ 16
gets() considers a whitespace as a part of the string and ends the input upon encountering \n or EOF. On the other hand scanf() ends taking input upon encountering a whitespace, \n and EOF.
scanf() allows to specifying the maximum character length to be scanned. Whereas in gets() it is not possible.
+ 9
gets() will register a line of input as a string up until the user hits enter, including spaces
scanf() will get input of the given format specifier up until it encounters a space or newline character
+ 4
Lets learn the basic way..
scanf() is used to read a single character from the user.Example-
scanf(%d,&num);
this will ask the user to input a single number
On the other hand, if we use gets() then the user can input a string(a bunch of characters) at a single go until you press the enter button.
+ 2
The main difference between gets and scanf is that scanf reads input until it encounters newline, whitespace or end of line where as gets reads the inputs until it encounter newline or end of line. It does not stop reading the input when it encounter with whitespace.