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

第二版《C程序语言设计》,P13,练习1-9。

#include <stdio.h>

/* count lines in input */
int
main()
{
        int c, pc; /* c = character, pc = previous character */

        /* set pc to a value that wouldn't match any character, in case
        this program is ever modified to get rid of multiples of other
        characters */

        pc = EOF;

        while ((c = getchar()) != EOF) {
                if (c == '')
                        if (pc != '')   /* or if (pc != c) */ 
                                putchar(c);

                /* We haven't met 'else' yet, so we have to be a little clumsy */
                if (c != '')
                        putchar(c);
                pc = c;
        }

        return 0;
}

代码来自网络。

站长数十年成长感悟,输入暗号查看

桩白墨公众号上还能加入书舟书友群、美团外卖红包群,免费领取站桩和原创 chatgpt 教程哦
暗号:
请关注本站微信公众号,回复“暗号”,即可获取。在微信里搜索“桩白墨”或者“baimoz”或者微信扫描右侧二维码都可以关注站长微信公众号。