From 49891f6bce29843f503b437c84d83cb787ecfa87 Mon Sep 17 00:00:00 2001 From: Zhineng Li Date: Sat, 10 Jan 2026 16:37:39 +0800 Subject: first commit --- ch01/ex12-print.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 ch01/ex12-print.c (limited to 'ch01/ex12-print.c') diff --git a/ch01/ex12-print.c b/ch01/ex12-print.c new file mode 100644 index 0000000..91aafa2 --- /dev/null +++ b/ch01/ex12-print.c @@ -0,0 +1,23 @@ +#include + +#define IN 1 /* inside a word */ +#define OUT 0 /* outside a word */ + +/* print one word per line from the input */ +int main() +{ + int c, state; + + state = OUT; + while ((c = getchar()) != EOF) { + if (c == ' ' || c == '\n' || c == '\t') { + if (state == IN) + putchar('\n'); + state = OUT; + } else if (state == OUT) + state = IN; + if (state == IN) + putchar(c); + } + putchar('\n'); +} -- cgit v1.2.3