练习1-12

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

 

 1 #include<stdio.h>
 2 #define IN 1 //在单词内
 3 #define OUT 0 //在单词外
 4 int main()
 5 {
 6     int c;
 7     int state = OUT;
 8     while ((c = getchar()) != EOF)
 9     {
10         if (c == ' ' || c == '\n' || c == '\t')
11         {
12             if (state==IN)
13             {
14                 putchar('\n');
15                 state = OUT;
16             }
17             
18         }
19         else if (state == OUT)
20         {
21             state = IN;
22             putchar(c);
23         }
24         else
25         {
26             putchar(c);
27         }
28     }
29     return 0;
30 }

 

posted @ 2016-03-05 16:07  CODESYS资源大全  阅读(147)  评论(0)    收藏  举报