DIGIT-ARC read-only archive · snapshot: July 23, 2026

doubt between fscanf and fgets

7 posts · originally from https://geek.digit.in/community/threads/doubt-between-fscanf-and-fgets.138721/

bijay_ps
bijay_ps Original post #1
Mar 31, 2011 at 8:32 PM
whats the difference between fscanf and fgets in file handling(In C)?
arpanmukherjee1
Mar 31, 2011 at 11:54 PM
fscanf does not perform bounds checking. fgets is likely going to be the better choice. You can then use sscanf() to evaluate it.

more info
IBM TPF Product Information Center
fscanf - C++ Reference
fgets - C++ Reference
scanf vs fgets?

BTW one more thing, never use scanf for input, use cin. Google it up if u want to know why, too many reasons for me to type
QwertyManiac
Apr 1, 2011 at 10:24 AM
Why suggest std::cin when the OP is using C, and confuse him?
arpanmukherjee1
Apr 1, 2011 at 11:05 AM
^^ yes i thought it too

but the advantage(s) of C++ over C must be kept in mind
bijay_ps
Apr 1, 2011 at 12:07 PM
thanks guys....
Liverpool_fan
Apr 1, 2011 at 12:40 PM
but the advantage(s) of C++ over C must be kept in mind
???
Not sure how std::cin can be an advantage of C++ over C? Only advantage I can think of that you have to specify the format for the input in scanf which is not needed in std::cin. However both exhibit similar behaviour since they are usually implemented as line buffered.
arpanmukherjee1
Apr 1, 2011 at 10:35 PM
^^ yes that, i'am sorry about the post.
i should have explained it.
reading this post now, i sound a lot like my coll professors

u explained it very well. thankyou