ex1-13.c 718 B

12345678910111213141516171819202122232425262728
  1. /*
  2. * Exercise 1-13. Write a program to print a histogram of the lengths of
  3. * words in its input. It is easy to draw the histogram with the bars
  4. * horizontal; a vertical orientation is more challenging.
  5. */
  6. #include <stdio.h>
  7. #define IN 1
  8. #define OUT 0
  9. main()
  10. {
  11. int c, state;
  12. state = OUT;
  13. while ((c = getchar()) != EOF) {
  14. if (c == ' ' || c == '\n' || c == '\t') {
  15. state = OUT;
  16. continue;
  17. } else if (state == OUT) {
  18. state = IN;
  19. putchar('\n');
  20. }
  21. if (state == IN) {
  22. putchar('*');
  23. }
  24. }
  25. }