From: Cian Bagshaw Date: Thu, 8 Dec 2022 11:41:25 +0000 (+0000) Subject: Added exercise 1-9 X-Git-Url: https://tests.cianb.xyz/?a=commitdiff_plain;h=228062fbb8cbba7a290227a888d4a55e17e409db;p=cProgLang Added exercise 1-9 --- diff --git a/1/9.c b/1/9.c new file mode 100644 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 + +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 */ + } +}