练习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 == '\n' || c == '\t'){
            if (last_ch == NOT_BLANK)
                putchar('\n');
            last_ch = BLANK;//这条语句可以包括在最近的if里面
        }else{
            putchar(c);
            last_ch = NOT_BLANK;
        }
    }
}
View Code

 

posted on 2013-09-17 10:48  Samuel Yang  阅读(303)  评论(0编辑  收藏  举报