Why doesn't this work? (3B2 problem)

jsdy at hadron.UUCP jsdy at hadron.UUCP
Sat Mar 22 19:04:53 AEST 1986


In article <276 at birtch.UUCP> ken at birtch.UUCP (Ken B) writes:
>We have a 3B2/300, and I wrote this program to help debug our spooler problem
>(another story), why doesn't it work?  It never read's an EOF from stdin,
>#include <stdio.h>
>main()
>{
>	int i=1;
>	char c;
>	c=getchar();
>	if (c!=EOF)

I'm not sure why this dumps NULs:  are you sure they are not DELs?
Anyway, I'd bet dollars to donuts (of which I have none) that the
3B2 does not sign-extend when converting from chars to ints.  The
return value of getchar is an int!  Therefore 'c' should be an int.
You see, EOF is supposed to be an int that is out-of-band for a
character.

Perhaps the 3B2 EOF is something with a high bit set and the low
byte 0?

If you want to avoid using fgets:
	while (fgets(bigbuf, sizeof(bigbuf), stdin) != NULL)
		printf("%d:\t%s", i++, bigbuf);
try this:
	register int i = 1;
	register int c;

	/* Number each line. */
	while ((c = getchar()) != EOF) {
		/* The number. */
		printf("%d:\t%c", i++, c);
		/* The line. */
		while ((c = getchar()) != EOF) {
			putchar(c);
			if (c == NL)
				break;
		}
		/* If you want to keep from extra passes: */
		if (feof(stdin))
			break;
	}
	return(0);	/* Always return a value to the environment. */
-- 

	Joe Yao		hadron!jsdy at seismo.{CSS.GOV,ARPA,UUCP}



More information about the Comp.lang.c mailing list