Mail Archives: djgpp/1997/06/13/13:49:09
Chris wrote:
>
> Hello All,
>
> I have a minor problem that probably has a simple solution that I have
> overlooked.
>
> When reading in binary files, I need to know how to stop when reaching
> the EOF.
>
> I know that stdio has a function fread but it doesn't check for end of
> file.
>
> What I am doing is reading in numbers as shorts and need a function
> that can do that with a binary file and stop at the EOF. How is this
> best accomplished.
Look at the info about fread.
FILE *f = fopen("file.nam", "rb");
while( fread( &myshort, sizeof(myshort), 1, f )){
do_what_you_like_with(myshort);
}
--
Ciao
Tom
*************************************************************
* Thomas Demmer *
* Lehrstuhl fuer Stroemungsmechanik *
* Ruhr-Uni-Bochum *
* Universitaetsstr. 150 *
* D-44780 Bochum *
* Tel: +49 234 700 6434 *
* Fax: +49 234 709 4162 *
* http://www.lstm.ruhr-uni-bochum.de/~demmer *
*************************************************************
- Raw text -