fgets() and fread() - What is the difference?

前端 未结 5 1587
旧巷少年郎
旧巷少年郎 2021-02-03 21:03

I understand the differences between fgets() and fgetss() but I don\'t get the difference between fgets() and fread()<

5条回答
  •  梦毁少年i
    2021-02-03 21:06

    fgets reads a line -- i.e. it will stop at a newline.

    fread reads raw data -- it will stop after a specified (or default) number of bytes, independently of any newline that might or might not be present.


    Speed is not a reason to use one over the other, as those two functions just don't do the same thing :

    • If you want to read a line, from a text file, then use fgets
    • If you want to read some data (not necessarily a line) from a file, then use fread.

提交回复
热议问题