Simple C Question (was: down)

John L. Furlani furlani at broadway.UUCP
Sun Dec 11 23:18:00 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


    This snippit of code should do it.  It will count the newlines, but it
won't count the returns.  

        while ((c = getc(infile)) != EOF)
            if (c == '\r') chcnt++;

    As for 'chcnt++ += (c == '\n')', you can't assign what is being 
incremented to anything.  This is different of course from '*count++ = 45'
where the pointer is being incremented and the info contained in the 
pointer is being assigned.


Flame?  Who us?

____________
Disclaimer:  "It's Mine! Mine! All Mine!!"
John L. Furlani 
The University of South Carolina, Columbia SC
(...!uunet!ncrlnk!ncrcae!broadway!furlani)



More information about the Comp.lang.c mailing list