1-12
authorCian Bagshaw <cian@cianb.xyz>
Tue, 20 Dec 2022 23:53:24 +0000 (23:53 +0000)
committerCian Bagshaw <cian@cianb.xyz>
Tue, 20 Dec 2022 23:53:24 +0000 (23:53 +0000)
1/12.c [new file with mode: 0644]

diff --git a/1/12.c b/1/12.c
new file mode 100644 (file)
index 0000000..5803164
--- /dev/null
+++ b/1/12.c
@@ -0,0 +1,22 @@
+/*
+       Exercise 1-12. Write a program that prints its input one word per line.
+       ===
+*/
+
+#include <stdio.h>
+
+int main () {
+       int c, w;
+
+       w=0;    /* word: 0=space, 1=word */
+       while ((c=getchar())!=EOF) {
+               if (c==' ' || c=='\t' || c=='\n')
+                       w=0;                    /* end word */
+               else if (!w) {          /* start word */
+                       w=1;                    
+                       putchar('\n');
+               }
+               if (w) putchar(c);      /* print word */                                
+       }
+       putchar('\n');
+}