练习1-12:编写一个程序,以每行一个单词的形式打印其输入(C程序设计语言 第2版)

#include <stdio.h>

#define NOT_BLANK 1
#define BLANK 0

main()
{
    int c;
    int last_ch = NOT_BLANK;

    while ((c=getchar()) != EOF){
        if (c == ' ' || c == '
' || c == '	'){
            if (last_ch == NOT_BLANK)
                putchar('
');
            last_ch = BLANK;//这条语句可以包括在最近的if里面
        }else{
            putchar(c);
            last_ch = NOT_BLANK;
        }
    }
}
View Code
原文地址:https://www.cnblogs.com/yangshuo/p/3325807.html