我最近开始使用K&R书(第2版)开始学习C,而我只是在思考这个解决方案时遇到麻烦,以便练习1-9,这是:
编写一个程序将其输入复制到其输出,用一个空格替换一个或多个空格的每个字符串.
我在网上找到了以下解决方案,除了putchar上面的分号('');它才有意义.没有它,程序不能正常执行其功能,该分号有什么功能?
#include <stdio.h>
int main(void)
{
int c;
while ((c = getchar()) != EOF) {
if(c == ' ') {
while((c = getchar()) == ' ')
;
putchar(' ');
}
putchar(c);
}
}
Run Code Online (Sandbox Code Playgroud)
提前致谢.