about summary refs log tree commit diff stats
path: root/1.6.c
blob: ae885213fb48ea90afa9e1552bbe9fe7fe1f750f (plain) (blame)
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
27
28
29
#include <stdio.h>
#define OUTWORD 0
#define INWORD  1
#define MAXWORDLEN 20

int main () {
	int c, i, wordlen;
	int ndigit[MAXWORDLEN] = {0};
    wordlen = 0;
    char state = OUTWORD;

	while ((c = getchar()) != EOF) {
		if (c == ' ' || c == '\n' || c == '\t') {
			if (state == INWORD) ++ndigit[wordlen];
            wordlen = 0;
            state = OUTWORD;
        }
		else {
            state = INWORD;
            ++wordlen;
        }
    }
	for (i = 0; i < MAXWORDLEN; ++i) {
		printf("%2d | ", i);
        for (int j = 0; j < ndigit[i]; ++j)
            printf("=");
        printf("%d\n", ndigit[i]);
    }
}