Difference between scanf() and fgets()

前端 未结 6 1239
灰色年华
灰色年华 2020-12-01 03:24

I want to know what is the difference between fgets() and scanf(). I am using C as my platform.

6条回答
  •  情书的邮戳
    2020-12-01 04:10

    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.

提交回复
热议问题