summaryrefslogtreecommitdiff
path: root/ch01/ex09-copy.c
diff options
context:
space:
mode:
Diffstat (limited to 'ch01/ex09-copy.c')
-rw-r--r--ch01/ex09-copy.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/ch01/ex09-copy.c b/ch01/ex09-copy.c
new file mode 100644
index 0000000..2303b83
--- /dev/null
+++ b/ch01/ex09-copy.c
@@ -0,0 +1,21 @@
+#include <stdio.h>
+
+/* merge consecutive blanks */
+int main()
+{
+ int c, b;
+
+ b = 0;
+ while ((c = getchar()) != EOF) {
+ if (c != ' ') {
+ putchar(c);
+ b = 0;
+ }
+
+ if (c == ' ') {
+ if (b == 0)
+ putchar(c);
+ b = 1;
+ }
+ }
+}