How to use read() to read data until the end of the file?

前端 未结 3 2257
不知归路
不知归路 2020-12-17 19:41

I\'m trying to read binary data in a C program with read() but EOF test doesn\'t work. Instead it keeps running forever reading the last bit of the file.

#in         


        
3条回答
  •  长情又很酷
    2020-12-17 20:06

    read returns the number of characters it read. When it reaches the end of the file, it won't be able to read any more (at all) and it'll return 0, not EOF.

提交回复
热议问题