shaobin0604
10/28/2009 - 2:11 AM

tcpl_1.5.4_wc.c

#include <stdio.h>

#define	IN	1 /* inside a word */
#define	OUT	0 /* outside a word */

int main(void)
{
	int c, nl, nc, nw, state;
	nl = nc = nw = 0;
	state = OUT;
	while ((c = getchar()) != EOF)
	{
		nc++;
		if (c == '\n')
			nl++;
		if (c == ' ' || c == '\t' || c == '\n')
			state = OUT;
		else if (state == OUT)
		{
			state = IN;
			nw++;
		}
	}
	printf("%d %d %d\n", nl, nw, nc);
	return 0;
}