Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

eof

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 I distinguish between the "real" end of a file, and the EOF character?

like image 560
polemon Avatar asked Feb 01 '12 05:02

polemon


1 Answers

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.

like image 158
Brian Roach Avatar answered Sep 16 '22 14:09

Brian Roach