Counting blanks



Hi I am new to this forum.

I have taken a class in C some time ago but now I am reading Kernigan
and Richie's book to refresh my knowledge. I think I have forgotten
alot and there are no solutions to the exercises. Maybe some people
here can check through some of my solutions.

Below is a solution to the exercise 1.8.

/* blank counter */

int x, y, z;

void main()
{
char c;

fflush(stdin); // start reading from stdin
while(! feof(stdin) ) {
switch(c = getchar()) {
case ' ' : x++; break;
case '\t': y++; break;
case '\n': z++;
}
}
fclose(stdin); // clean up

printf("[spaces, tabs, newlines] = [%d, %d, %d]\n", x, y, z);
}
.


Quantcast