How do I distinguish between an EOF character, and the actual end of file?

前端 未结 3 1211
无人及你
无人及你 2021-01-13 02:09

When reading a file, I understand the last character provided is an EOF. Now, what happens, when I have an EOF character in that file?

How do

3条回答
  •  萌比男神i
    2021-01-13 02:38

    I decided to move my comments to an answer.

    You can't have an "EOF character" in your file because there is no such thing. The underlying filesystem knows how many bytes are in a file; it doesn't rely on the contents of the file to know where the end is.

    The C functions you're using return EOF (-1) but that wasn't read from the file. It's just the way the function tells you that you're reached the end. And because -1 isn't a valid character in any character set, there's no confusion.

提交回复
热议问题