1 /* $NetBSD: mywc.c,v 1.1.1.1 2009/10/26 00:28:34 christos Exp $ */ 2 3 /* A simple but fairly efficient C version of the Unix "wc" tool */ 4 5 #include <stdio.h> 6 #include <ctype.h> 7 8 main() 9 { 10 register int c, cc = 0, wc = 0, lc = 0; 11 FILE *f = stdin; 12 13 while ((c = getc(f)) != EOF) { 14 ++cc; 15 if (isgraph(c)) { 16 ++wc; 17 do { 18 c = getc(f); 19 if (c == EOF) 20 goto done; 21 ++cc; 22 } while (isgraph(c)); 23 } 24 if (c == '\n') 25 ++lc; 26 } 27 done: printf( "%8d%8d%8d\n", lc, wc, cc ); 28 } 29