gpt4 book ai didi

c - K&R - 练习 1-9 - 删除空格

转载 作者:太空狗 更新时间:2023-10-29 16:42:38 25 4
gpt4 key购买 nike

<分区>

我最近开始使用 K&R 书(第 2 版)学习 C,但我无法全神贯注于练习 1-9 的解决方案,即:

Write a program to copy its input to its output, replacing each string of one or more blanks by a single blank.

我在网上找到了以下解决方案,除了 putchar(' '); 上面的那个分号外,它大部分都是有意义的。没有它程序就不能正常执行它的功能,那个分号有什么作用?

#include <stdio.h>

int main(void)
{
int c;

while ((c = getchar()) != EOF) {
if(c == ' ') {
while((c = getchar()) == ' ')
;
putchar(' ');
}
putchar(c);
}
}

提前致谢。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com