down
Sun NCAA
matthew at sunpix.UUCP
Mon Dec 12 07:58:26 AEST 1988
In article <gables.352 at umigw.miami.edu>, slores%gables.span at umigw.miami.edu (Stanislaw L. Olejniczak) writes:
> PLEASE don't flame for posting too simple a question. I think the following
> SHOULD work, but will not even compile:
> while ( (c = getchar) != EOF)
> chcnt++ += (c == '\n');
> The purpose is to count characters in a file. Each time a newline is
> encountered an additional character should be counted: when the file is
> transferred, a newline is CR-LF combination.
I'm not sure about the validity of the construct 'chcnt++ += (c == '\n');', but
I'd write your program scrap as:
while ( (c = getchar) != EOF)
{
if (c == '\n')
chcnt++;
chcnt++;
}
(Before closing, there is one logic flaw in your scrap of code. '(c == '\n')'
does not have to evaluate to an integer 1. It must only be a non-zero value if
true.)
--
Matthew Lee Stier (919) 469-8300|
Sun Microsystems --- RTP, NC 27560| "Wisconsin Escapee"
uucp: {sun, rti}!sunpix!matthew |
More information about the Comp.lang.c
mailing list