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

前端 未结 5 1584
旧巷少年郎
旧巷少年郎 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条回答
  •  一整个雨季
    2021-02-03 21:22

    The function fgets reads a single line from a text file. It is reading so long until the end of the current line (or the end of the file) is reached. Therefore, if you would like to read one line from a text file, you should use fgets. The function fread not only reads until the end of the line but to the end of the file [e.g. fread($handle)] or as many bytes as specified as a parameter [e.g. fread($handle, 1024)]. So, if you would like to read a complete file, no matter whether it is a text file with all containing lines or arbitrary raw data from a file, you should use fread.

提交回复
热议问题