Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

EOF - what the char it is exatly, and what to do if it inside of file? 1

Status
Not open for further replies.

alex5161

Programmer
Jun 30, 2005
3
US
Hi,
I have to work with files, that were created from database records. It is binary. Any character is possible to be there. It is possible to have some character as EOF.
Also I do not know, what is the code for EOF?
How to handle a situation when data would have the same character as the EOF? How to be shure, that by check on the EOF I actualy have the end of file and not any data character in a midle?

Appreciate your help!
 
All right, DaveSinkula, thank you for link, I've red this with interest, and it is good to know.
But my question still not cleared.

I've get, that the EOF is int and = FFFF and unsigned char never could be equal to it.
But in our company all programs work with int, instead of char, everything is processed in 16-base representation.
I do not see any reason why anywhere in data it could not be -1 (FFFF)
Although this article mentioned about 'EOF is a macro defined as an int with a negative value', it is still unclear how it is really provide assurance that the -1 value is result of end-of-file instead of any internal value.
 
Outside of DOS, EOF is not a character in the file. It is a value returned by several functions to indicate end-of-file has been reached. But most files do not actually contain an "EOF character".

It's value is implemented with -1 on many systems, but as a C programmer you aren't supposed to care -- just use the macro EOF.
 
Thank you again, DaveSinkula, now I comfortable with EOF.
Appreciate you help!
 
More precisely: it's 0x1A character denotes end of file in DOS, not EOF value (CP/M OS heritage;).
 
Just to comment on some thoughts:

<qoute>I do not see any reason why anywhere in data it could not be -1 (FFFF)</qoute>

There can't be an unsigned char of value -1, because it's unsigned. Though, the return value is signed int, so when you call fgetc, you get values 0-255 for any legal char in file, and -1 to indicate EOF or whatever error there was.
Simple... I guess.

------------------
When you do it, do it right.
 
just for information: This thread began with binary files.
Obviously DOS didn't (doesn't) use any particular number to mark the end of a binary file. In fact I'm not aware of EOF serving any particularly useful function in DOS...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top