EOF considered harmful

Ian Cottam ian at r6.uucp
Tue Oct 24 21:13:38 AEST 1989


In article <266 at m1.cs.man.ac.uk> ian at r6.UUCP I (Ian Cottam) write:
>Some observations on the little program below (following some recent
>discussions in this group):
>_______________________
>#include <stdio.h>
>
>int
>main()
>{
>	char ch;
>	while ( ! feof(stdin) ) {
>		ch= getchar();
>		putchar(ch);
>	}
>
>	return 0;
>}
>______________________
Whoops! Red face!  Is this any better (he says cautiously)?
_______
#include <stdio.h>

int
main()
{
	char ch;
	for(;;) {
		ch= getchar();
		if ( feof(stdin) || ferror(stdin) )
			break;
		else
			putchar(ch);
	}

	return 0;
}
_________


-----------------------------------------------------------------
Ian Cottam, Room IT101, Department of Computer Science,
University of Manchester, Oxford Road, Manchester, M13 9PL, U.K.
Tel: (+44) 61-275 6157         FAX: (+44) 61-275-6280
Internet: ian%cs.man.ac.uk at nss.cs.ucl.ac.uk   
JANET: ian at uk.ac.man.cs    UUCP: ..!mcvax!ukc!man.cs!ian
-----------------------------------------------------------------



More information about the Comp.lang.c mailing list