www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/17/08:12:09

Sender: crough45 AT amc DOT de
Message-Id: <97Jul17.140456gmt+0100.16641@internet01.amc.de>
Date: Thu, 17 Jul 1997 13:09:02 +0100
From: Chris Croughton <crough45 AT amc DOT de>
Mime-Version: 1.0
To: asu1 AT cornell DOT edu
Cc: djgpp AT delorie DOT com
Subject: Re: fread/fwite return value

A. Sinan Unur wrote:

>  while( fread(&c, 1, 1, f) )
>    printf("%c", c);

While this is correct according to ANSI C, I prefer
to do:

  while( fread(&c, 1, 1, f) > 0 )
    printf("%c", c);

just in case it returns a negative value (some Unix
systems have done that to me in the past).  Defensive
programming.  OK, paranoid programming <g>...

(I fail to see, however, why using fread is any better
than using getc; it's a lot less efficient for a single
character in most implementations...)

Chris C

- Raw text -


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