delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/09/23/14:32:46

From: "A. Sinan Unur" <asu1 AT cornell DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: what's the equivalent of <iostream.h> for gpp ?
Date: 23 Sep 2001 18:18:16 GMT
Organization: Cornell University
Lines: 53
Sender: asu1 AT cornell DOT invalid (on slip-32-102-40-235.ny.us.prserv.net)
Message-ID: <Xns91259183D905CASINANUNUR@132.236.56.8>
References: <01c14445$8cc5f3e0$bc8684d5 AT feta> <01c14449$4c5c3fe0$bc8684d5 AT feta>
NNTP-Posting-Host: slip-32-102-40-235.ny.us.prserv.net
X-Trace: news01.cit.cornell.edu 1001269096 14359 32.102.40.235 (23 Sep 2001 18:18:16 GMT)
X-Complaints-To: usenet AT news01 DOT cit DOT cornell DOT edu
NNTP-Posting-Date: 23 Sep 2001 18:18:16 GMT
User-Agent: Xnews/4.06.22
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

"Gwen" <mb11363 AT chello DOT be> wrote in news:01c14449$4c5c3fe0$bc8684d5 AT feta:

>> 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); }

how is this supposed to work? you are only reading one character out of the 
file.

try something like this:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
	int c;
	FILE *fin;

	fin = fopen(argv[1], "rt");
	if( fin == NULL )
	{
		perror(argv[1]);
		exit(EXIT_FAILURE);
	}

	while( (c = getc(fin)) != EOF)
		if( c != '\n' ) putc(c, stdout);

	return 0;
}

> 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. 

it is impossobile to know what error you made without seeing the code that 
you actually used.

hth.

sinan.


-- 
--------------------------------
A. Sinan Unur
http://www.unur.com/

- Raw text -


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