From: Thomas Demmer Newsgroups: comp.os.msdos.djgpp,comp.lang.c++ Subject: Re: Reading binary files Date: Fri, 13 Jun 1997 15:46:15 +0100 Organization: Lehrstuhl fuer Stroemungsmechanik Lines: 38 Message-ID: <33A15D37.446B@LSTM.Ruhr-UNI-Bochum.De> References: <33a13a3a DOT 2140316 AT supernews DOT scsn DOT net> NNTP-Posting-Host: bvb.lstm.ruhr-uni-bochum.de Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk 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 * *************************************************************