From: Cian Bagshaw Date: Tue, 20 Dec 2022 23:53:24 +0000 (+0000) Subject: 1-12 X-Git-Url: https://tests.cianb.xyz/?a=commitdiff_plain;h=e1f835ee48380bf97a1af779d472e62c5b748bd6;p=cProgLang 1-12 --- diff --git a/1/12.c b/1/12.c new file mode 100644 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 + +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'); +}