12345678910111213141516171819202122232425262728 |
- /*
- * Exercise 1-13. Write a program to print a histogram of the lengths of
- * words in its input. It is easy to draw the histogram with the bars
- * horizontal; a vertical orientation is more challenging.
- */
- #include <stdio.h>
- #define IN 1
- #define OUT 0
- main()
- {
- int c, state;
- state = OUT;
- while ((c = getchar()) != EOF) {
- if (c == ' ' || c == '\n' || c == '\t') {
- state = OUT;
- continue;
- } else if (state == OUT) {
- state = IN;
- putchar('\n');
- }
- if (state == IN) {
- putchar('*');
- }
- }
- }
|