Blob
1 #include <stdio.h>3 #define IN 1 /* inside a word */4 #define OUT 0 /* outside a word */6 /* count lines, words, and characters in input */7 main()8 {9 int c, nl, nw, nc, state;11 state = OUT;12 nl = nw = nc = 0;13 while ((c = getchar()) != EOF) {14 ++nc;15 if (c == '\n')16 ++nl;17 if (c == ' ' || c == '\n' || c == '\t')18 state = OUT;19 else if (state == OUT) {20 state = IN;21 ++nw;22 }23 }24 printf("%d %d %d\n", nl, nw, nc);25 }