Difference between scanf() and fgets()

前端 未结 6 1219
灰色年华
灰色年华 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:07

    Scanf does not perform bounds checking. fgets is likely going to be the better choice. You can then use sscanf() to evaluate it.

    Good discussion of the topic here- http://cboard.cprogramming.com/c-programming/109243-scanf-vs-fgets.html

    How do you allow spaces to be entered using scanf? (That was my evil twin getting lectured for forgetting this- not me)

提交回复
热议问题