gets() or fgets() in c ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

gets() or fgets() in c ?

Hi friends, I wanted to know what is the difference between the two functions of gets() and fgets? Who knows?

2nd Aug 2020, 9:19 PM
Morteza R.g
Morteza R.g - avatar
3 Answers
+ 3
Thank you all.
4th Aug 2020, 6:15 AM
Morteza R.g
Morteza R.g - avatar
+ 1
Morteza R.g gets() do not do any array bound testing thus is prone to buffer overflow which makes it dangerous to use in your program (just like Martin Taylor said) Whereas on the other hand while using fgets() one has to to specify the maximum amount of characters to be read by it hence making it safer to use.
3rd Aug 2020, 2:04 AM
Arsenic
Arsenic - avatar