Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!decvax!mcnc!akgua!gatech!seismo!rlgvax!hadron!jsdy From: jsdy@hadron.UUCP Newsgroups: net.lang.c,net.micro.att Subject: Re: Why doesn't this work? (3B2 problem) Message-ID: <323@hadron.UUCP> Date: Sat, 22-Mar-86 04:04:53 EST Article-I.D.: hadron.323 Posted: Sat Mar 22 04:04:53 1986 Date-Received: Mon, 24-Mar-86 18:30:09 EST References: <276@birtch.UUCP> Reply-To: jsdy@hadron.UUCP (Joseph S. D. Yao) Distribution: na Organization: Hadron, Inc., Fairfax, VA Lines: 46 Xref: mcnc net.lang.c:5068 net.micro.att:1080 Summary: unsigned char != EOF always. In article <276@birtch.UUCP> ken@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 >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@seismo.{CSS.GOV,ARPA,UUCP}