wc.c (321B)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <stdio.h> int main() { long nc, nw, nl; int c; char inWord; nc = nw = nl = 0; while ((c = getchar()) != EOF) { if (c == '\n') ++nl; if (c == ' ' || c == '\t' || c == '\n') inWord=0; else if (inWord == 0) { inWord = 1; ++nw; } ++nc; } printf(" %ld %ld %ld\n", nl, nw, nc); return 0; }