Counting blanks
- From: rajash@xxxxxxxxxxxxxxxxxxxxxxxx
- Date: Fri, 30 Nov 2007 13:54:11 -0800 (PST)
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);
}
.
- Prev by Date: Re: Multi precision floating point
- Next by Date: Re: Very interesting GC discussion
- Previous by thread: Win32: C: Chinese language inputting improperly in text box. Extremely strange bug, please help!
- Index(es):