Mail Archives: djgpp/2001/09/23/14:32:46
"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 -