C 语言 习题 1-9

练习1-9 编写一个将输入复制到输出的程序,并将其中连续的多个空格用一个空格代替。

 1 #include <stdio.h>
 2 
 3 int main(int argc, char const *argv[])
 4 {
 5     int c, pc;
 6     
 7     pc = EOF;
 8     
 9     while ((c = getchar()) != EOF)
10     {
11         if (c == ' ')
12             if (pc != c)
13                 putchar(c);
14         if (c != ' ')
15             putchar(c);
16         
17         pc = c;
18     }
19 
20     return 0;
21 }

 

posted @ 2017-10-10 13:50  berthua  阅读(334)  评论(0编辑  收藏  举报