delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/06/13/13:49:09

From: Thomas Demmer <demmer AT LSTM DOT Ruhr-UNI-Bochum DOT De>
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
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019