3.以每行一个单词的形式打印其输入

#include 

#define IN 1
#define OUT 0

int main()
{
    int c, state;

    state = OUT;

    while ((c = getchar()) != EOF) {
        if (c == ' ' || c == '\n' || c == '\t') {
        //如果是单词分隔符,且state == IN,表明是单词的结束
            if (state == IN) {
                putchar('\n');
                state = OUT;
            }
        } else if (state == OUT) {
            state = IN;
            putchar(c);
        } else {
            putchar(c);
        }
    }
}

你可能感兴趣的:(3.以每行一个单词的形式打印其输入)