ex1-9.c 387 B

1234567891011121314151617181920212223242526
  1. /*
  2. * Exercise 1-9. Write a program to copy its input to its output, replacing
  3. * each string of one or more blanks by a single blank.
  4. */
  5. #include <stdio.h>
  6. #include <stdbool.h>
  7. main()
  8. {
  9. int c;
  10. bool in_space = false;
  11. while ((c = getchar()) != EOF) {
  12. if (c == ' ') {
  13. if (in_space)
  14. continue;
  15. else
  16. in_space = true;
  17. } else
  18. in_space = false;
  19. putchar(c);
  20. }
  21. }