summaryrefslogtreecommitdiff
path: root/examples/fastwc/mywc.c
blob: 92e5a366c12884cf71c8f5a50966adec34b04fdc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/* A simple but fairly efficient C version of the Unix "wc" tool */

#include <stdio.h>
#include <ctype.h>

main()
{
	register int c, cc = 0, wc = 0, lc = 0;
	FILE *f = stdin;

	while ((c = getc(f)) != EOF) {
		++cc;
		if (isgraph(c)) {
			++wc;
			do {
				c = getc(f);
				if (c == EOF)
					goto done;
				++cc;
			} while (isgraph(c));
		}
		if (c == '\n')
			++lc;
	}
done:	printf( "%8d%8d%8d\n", lc, wc, cc );
}