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

前端 未结 5 1586
旧巷少年郎
旧巷少年郎 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:18

    The accepted answer is correct, but there is one more case for fread to stop reading. fread has a chunk limit of 8192 bytes. I discovered this when I was getting different results from fread($stream, 8300) and fget($stream, 8300).

    From fread docs:

    if the stream is read buffered and it does not represent a plain file, at most one read of up to a number of bytes equal to the chunk size (usually 8192) is made; depending on the previously buffered data, the size of the returned data may be larger than the chunk size.

提交回复
热议问题