Added exercise 1-9
authorCian Bagshaw <cian@cianb.xyz>
Thu, 8 Dec 2022 11:41:25 +0000 (11:41 +0000)
committerCian Bagshaw <cian@cianb.xyz>
Thu, 8 Dec 2022 11:41:25 +0000 (11:41 +0000)
1/9.c [new file with mode: 0644]

diff --git a/1/9.c b/1/9.c
new file mode 100644 (file)
index 0000000..a930160
--- /dev/null
+++ b/1/9.c
@@ -0,0 +1,18 @@
+/*
+       Exercise 1-9. Write a program to copy its input to its output, replacing each
+       string of one or more blanks by a single blank.
+       ===
+*/
+
+#include <stdio.h>
+
+int main () {
+       int c, w;
+
+       w=0;    /* word: 0=space, 1=word */
+       while ((c=getchar())!=EOF) {
+               if (c!=' ' && !w) w=1;  /* word begins */
+               if (w) putchar(c);              /* print character */
+               if (c==' ' && w) w=0;   /* word ends */
+       }
+}