Commits

sunqiang committed cfa4df6

another version of ch1.5.4 ex 1.9

Comments (0)

Files changed (1)

ch01/05/09.ex1.9/main.c

 #include <stdio.h>
+#define IN 1
+#define OUT 0
 
 /* Write a program to copy its input to its output, replacing
  * each string of one or more blanks by a single blank. */
 int main(void)
 {
-    int c;
-    int inblank;
+    int c, status;
+    status = OUT;
 
-    inblank = 0;
     while ((c = getchar()) != EOF) {
         if (c == ' ') {
-            if (inblank) {
-                ;
-            } else {
-                inblank = 1;
+            if (status == OUT) {
+                status = IN;
                 putchar(c);
             }
         } else {
-            inblank = 0;
+            status = OUT;
             putchar(c);
         }
     }