What's difference between gets() and scanf() function? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What's difference between gets() and scanf() function?

12th Aug 2019, 4:50 PM
Kiruthiga
2 Answers
+ 2
Scanf provides a format string for formatted input.
12th Aug 2019, 11:49 PM
Sonic
Sonic - avatar
+ 2
As Sonic said Scanf() provides a format string for formatted output.. Scanf is used to take any input whether it is int, float, char or a string while gets() can take Only string as an input.. Now, question is scanf() can also take string as an input then why do we use gets()? Answer is scanf() will take input only upto the first blank space occurs while gets() will take input upto first new line.. For eg. Input:- Hello World Scanf() will take input upto Hello while gets will take whole string i.e Hello World
13th Aug 2019, 2:32 AM
Alaska
Alaska - avatar