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 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 , djgpp AT delorie DOT com Subject: Re: what's the equivalent of for gpp ? References: <01c14445$8cc5f3e0$bc8684d5 AT feta> <01c14449$4c5c3fe0$bc8684d5 AT feta> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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.