Syntax rewrite, more docs
[tcpl.git] / ch1 / 09.c
blob27406ee5640e84e9d2547b79c73e4cba93a5bf9e
1 /*
2 * Exercise 1-9:
3 * Write a program to copy its input to its output, replacing each string of one or more blanks by a
4 * single blank.
5 */
7 #include <stdlib.h>
8 #include <stdio.h>
10 int
11 main(void)
13 // Read all input until EOF.
14 int c;
15 while ((c = getchar()) != EOF) {
17 * Upon reaching a space, print said space, and then keep looping
18 * until we get back to non-space characters.
20 if (c == ' ') {
21 putchar(c);
22 while ((c = getchar()) == ' ' && c != EOF)
26 if (c == EOF)
27 break;
29 putchar(c);
32 return EXIT_SUCCESS;