练习1-12 编写一个程序,以每行一个单词的形式打印其输入。
#include <stdio.h>
#define IN 1 /* 在单词内 */
#define OUT 0 /* 在单词外 */
int main(int argc, char *argv[])
{
(void)argc;
(void)argv;
int c;
int state = OUT;
while((c = getchar()) != EOF) {
if (c == ' ' || c == '\n' || c == '\t') {
if (IN == state) {
putchar('\n');
}
state = OUT;
}
else if (OUT == state) {
state = IN;
}
if (IN == state) {
putchar(c);
}
}
return 0;
}
运行结果: