There are multiple differences. Two crucial ones are:
fgets()
can read from any open file, but scanf()
only reads standard input.
fgets()
reads 'a line of text' from a file; scanf()
can be used for that but also handles conversions from string to built in numeric types.
Many people will use fgets()
to read a line of data and then use sscanf()
to dissect it.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…