Added example 5-14. Sorts data from stdin. Has some issues.
[C-Programming-Examples.git] / word_count.c
blob0f4b19c306b962ae8ceb58202a5770c5b4039d24
1 #include <stdio.h>
3 #define IN 1
4 #define OUT 0
6 main()
8 int c, nl, nw, nc, state;
10 state = OUT;
12 nl = nw = nc = 0;
13 while ((c = getchar()) != EOF)
15 ++nc;
16 if(c == '\n')
17 ++nl;
18 if(c == ' ' || c == '\n' || c == '\t')
19 state = OUT;
20 else if(state == OUT)
22 state = IN;
23 ++nw;
26 printf("%d %d %d\n", nl, nw, nc);