From 9706f875156e5ce4c08444489b634c54f4d62b52 Mon Sep 17 00:00:00 2001 From: Adam Carpenter <53hornet@gmail.com> Date: Tue, 14 May 2019 13:30:53 -0400 Subject: Finished 1.16 --- word_hist.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 word_hist.c (limited to 'word_hist.c') 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 + +/* + * 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; + } +} -- cgit v1.2.3