summaryrefslogtreecommitdiff
path: root/word_hist.c
blob: 965c1b9131b414630da11b2f4629bf05f3e1bd4f (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
#include<stdio.h>

/*
 * Prints a histogram of the lengths of words in its input.
 */
main() {
    int c;
    int count;

    while ((c = getchar()) != EOF) {
        if (c == '\n' || c == '\t' || c == ' ') {

            while (count > 0) {
                printf("%s", "*");
                --count;
            }

            if (count > 0) {
                printf("\n");
            }
        } else
            ++count;
    }
}