小编sla*_*axx的帖子

K&R练习1-9:输出输入,用一个空格替换多个空格

我一直在研究一些关于C的书,试图得到我的C腿(海腿!得到它?!).我刚从K&R书中完成了练习1-9,其参考是"编写一个程序将其输入复制到其输出中,用一个空格替换一个或多个空格的每个字符串." 我对我的代码发生了什么问题,但是 -

#include <stdio.h>

//Copy input to output. Replace each string of multiple spaces with one single space

int main(int argc, char *argv[]){

    int ch, lch;      // Variables to hold the current and last characters, respectively


    /* This loop should 'put' the current char, then store the current char in lc,
     * loop back, 'get' a new char and check if current and previous chars are both spaces.
     * If both are spaces, do nothing. Otherwise, 'put' the current …
Run Code Online (Sandbox Code Playgroud)

c kernighan-and-ritchie

34
推荐指数
6
解决办法
2939
查看次数

标签 统计

c ×1

kernighan-and-ritchie ×1