c语言:编写一个将输入复制到输出的程序,并将其中的多个空格用一个空格代替...

《c语言程序设计 第二版》上的题目

1.编写一个将输入复制到输出的程序,并将其中的多个空格用一个空格代替?

直接看代码:

仅供参考,代码来源于互联网!!!

代码一:

 1 #include "stdio.h"
2
3 main()
4 {
5 int c;
6 int i;
7 int n = 0;
8
9 while ( (c = getchar()) != EOF)
10 {
11 if ( c != '' )
12 {
13 putchar(c);
14 }
15 else if ( n != '')
16 {
17 putchar(c);
18 }
19
20 n = c;
21 }
22 }

代码二(详细):

 1 #include <stdio.h>
2
3 /* count lines in input */
4 int
5 main()
6 {
7 int c, pc; /* c = character, pc = previous character */
8
9 /* set pc to a value that wouldn't match any character, in case
10 this program is ever modified to get rid of multiples of other
11 characters */
12
13 pc = EOF;
14
15 while ((c = getchar()) != EOF) {
16 if (c == '')
17 if (pc != '') /* or if (pc != c) */
18 putchar(c);
19
20 /* We haven't met 'else' yet, so we have to be a little clumsy */
21 if (c != '')
22 putchar(c);
23 pc = c;
24 }
25
26 return 0;
27 }


PS:偶看了真是泪流满面,泪奔~~o(>_<)o ~~

转载于:https://www.cnblogs.com/fhefh/archive/2011/10/28/2227961.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值