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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

end-of-file

Status
Not open for further replies.

raghu75

Programmer
Nov 21, 2000
66
IN
Can anyone help me how to look for end-of-file when using "fread" to read data from a binary file.
 
there is a function:
feof(yourFilePointer) what returns is the end or not. John Fill
1c.bmp


ivfmd@mail.md
 
Sorry its not working for the code below...

fwrite(&size,sizeof(size),1,pUserFile);
fclose(pUserFile);

pUserFile = fopen(some file,"r");
while(!feof(pUserFile))
{
fread(&size,sizeof(size),1,pUserFile);
}
After reading the written item it loops once again and then finds EOF...why?????
 
try something like it. The function returns 1 on failure.
if(fread(&size,sizeof(size),1,pUserFile))break;
John Fill
1c.bmp


ivfmd@mail.md
 
I think, you can skip the EOF while reading. In my opinion it is a bug. John Fill
1c.bmp


ivfmd@mail.md
 
The reason is because if your file is 10 chars in length and you read 10 chars you are not at the end of the file. When you try to read again the eof marker is read and you are now at the end of the file. I hope this helps.
TM

 
But when u read it agian after 10 chars it is not coming out of the loop,ie.EOF is not found.Why???
 
I don't know exactly what do theese functions do, but sometines hay happend the program to never find the end of file. In theese cases, you should do some workaround. John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top