C - The C Answer (2nd Edition) - Exercise 1-12

来源:互联网 发布:优艺客软件 编辑:程序博客网 时间:2024/05/12 00:34
/* Write a program that prints its input one word per line. */#include <stdio.h>#define IN  1  /* inside a word  */#define OUT 0  /* outside a word *//* print input one word per line */main(){int c, state = OUT;while((c = getchar()) != EOF){if(c == ' ' || c == '\n' || c == '\t'){if(state == IN){putchar('\n');  /* finish the word */state = OUT;}else if(state == OUT){state = IN;  /* beginning of word */putchar(c);}else  /* inside a word */{putchar(c);}}}}
1 0