feof (end of file) not recognized.
Hi,
I wrote a random access data file using fwrite.
I then read it doing
while(!feof){}
but it doesn''t see the feof and keeps going.
Do I have to write a special feof character? I know its ctl-z for windows, but how do I write this at the end of a file?
thanx
(I''m using C, not c++ and its a console program)
feof is a function. Your code is testing whether its address is not 0. Which it will never be. You need to actually call the function : while( !feof( fp ) ) { /* ... */ } where fp if your file pointer.
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
Yes, soory, that was an ommision in my post, but not my code.
my code is
while (!feof(cfPtr)){
fread(&dx,sizeof(dx),1,cfPtr);
fseek(cfPtr,sizeof(dx),SEEK_CUR);
fread(&dy,sizeof(dy),1,cfPtr);
printf("dx: %d /t dy: %d \n", dx, dy);
fseek(cfPtr,sizeof(dy),SEEK_CUR);
}
my code is
while (!feof(cfPtr)){
fread(&dx,sizeof(dx),1,cfPtr);
fseek(cfPtr,sizeof(dx),SEEK_CUR);
fread(&dy,sizeof(dy),1,cfPtr);
printf("dx: %d /t dy: %d \n", dx, dy);
fseek(cfPtr,sizeof(dy),SEEK_CUR);
}
You don''t need to seek after a read. You''re probably seeking past the end of the file. I don''t know what feof returns in that case.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement