C 习题

练习 1 - 12 编写一个程序,以每行一个单词的形式打印其输出。

/* ex12.c */
#include 

#define IN      1
#define OUT     0

int main() {
        int c;
        int inword = OUT;

        while ((c = getchar()) != EOF) {
                if (c == ' ' || c == '\n' || c == '\t') {
                        if (inword) {
                                putchar('\n');
                                inword = OUT;
                        }
                } else {
                        putchar(c);
                        inword = IN;
                }
        }

        return 0;
}

编译运行结果:

$ ./ex12.out 
april  is  a  dog's dream
april
is
a
dog's
dream
$ 

你可能感兴趣的:(C 习题)