One more point regarding = and == (more flamage)

Christopher R Volpe volpe at camelback.crd.ge.com
Mon Apr 8 23:28:05 AEST 1991


In article <1991Apr4.215605.2801 at syssoft.com>, tom at syssoft.com
(Rodentia) writes:
|>In article <3465 at litchi.bbn.com> rsalz at bbn.com (Rich Salz) writes:
|>>In <3555 at inews.intel.com> bhoughto at hopi.intel.com (Blair P. Houghton)
writes:
|>>>toupper.c:    while ( (int) (c = getchar()) != EOF )
|>>The cast implies that c is char.  If so, this line is buggy.
|>
|>Does this mean that there if c is char, there is no way to assign the
|>getchar and test it for EOF without having it cast down to char?

c simply shouldn't be a char. It should be an int, since that is what
getchar returns. getchar can't return a char because it has to return
257 distinct values: all 256 values of char, plus the value EOF.

Write it like this:
int c;
...
while ((c=getchar()) != EOF) {...};

|>Thomas Roden                                      | tom at syssoft.com
|>Systems and Software, Inc.                        | Voice: (714)
833-1700 x454 
|>"If the Beagle had sailed here, Darwin would have | FAX:   (714) 833-1900
|>come up with a different theory altogether." - me |
                 
==================
Chris Volpe
G.E. Corporate R&D
volpecr at crd.ge.com



More information about the Comp.lang.c mailing list