diff options
author | Adam Carpenter <53hornet@gmail.com> | 2019-05-14 13:30:53 -0400 |
---|---|---|
committer | Adam Carpenter <53hornet@gmail.com> | 2019-05-14 13:30:53 -0400 |
commit | 9706f875156e5ce4c08444489b634c54f4d62b52 (patch) | |
tree | 706a30846a7237b4eb05d5acfd840fbeba890c22 /word_hist.c | |
parent | e0ac6e6a3c74f0e4d5936462eaae4d450fa3ed43 (diff) | |
download | learning-c-9706f875156e5ce4c08444489b634c54f4d62b52.tar.xz learning-c-9706f875156e5ce4c08444489b634c54f4d62b52.zip |
Finished 1.16
Diffstat (limited to 'word_hist.c')
-rw-r--r-- | word_hist.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/word_hist.c b/word_hist.c new file mode 100644 index 0000000..965c1b9 --- /dev/null +++ b/word_hist.c @@ -0,0 +1,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; + } +} |