www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/09/24/03:00:13

Sender: tim AT mxrelay DOT g-net DOT be
Message-ID: <3BAED94A.E957ABFD@falconsoft.be>
Date: Mon, 24 Sep 2001 08:57:14 +0200
From: Tim Van Holder <tim DOT vanholder AT falconsoft DOT be>
Organization: Anubex (www.anubex.com)
X-Mailer: Mozilla 4.78 [en] (X11; U; Linux 2.2.16-3 i686)
X-Accept-Language: en, nl-BE, nl
MIME-Version: 1.0
To: Gwen <mb11363 AT chello DOT be>, djgpp AT delorie DOT com
Subject: Re: what's the equivalent of <iostream.h> for gpp ?
References: <01c14445$8cc5f3e0$bc8684d5 AT feta> <01c14449$4c5c3fe0$bc8684d5 AT feta>
Reply-To: djgpp AT delorie DOT com

Gwen wrote:
> 
> > I'm experiencing some problems with stdio.h and I want to use iostream.h,
> In fact, I think I'll have the same problems with iostream.h : I can't
> recognize when I read a file when there is a carriage return.
> I tried this :
> 
> int c=getc(f);
> while (c!=13) { addch(c); }
> 
> It displays all the characteres of my files, with the cariage return but it
> doesn't break the loop and it reachs the end of file and loops forever.

The main problem is that for a file opened in text mode (the default),
CR/LF pairs are read as a signle LF.  So if it's a text file you're
reading,
there's a good chance you'll never see a CR.  Try using fopen(file,
"rb")
instead of fopen(file, "r").
Besides, you should always be very defensive in input loops like that;
at the
very least, you should break out of the loop if you reach EOF.  I think
the
example above also omits the 'c = getc(f)' inside the loop body.

- Raw text -


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