您的位置:首页 > 编程语言 > PHP开发

The C programming language-Exercise 1-9

2011-10-17 14:53 375 查看
Write a program to copy its input to its output, replacing each string of one or more blanks by a single blank.

我做的答案是:

#include<stdio.h>
main()
{
int c,nb;
c=nb=getchar();
while(c != EOF)
{
while (c == ' ')
{
nb=c;
c=getchar();
}
if(nb != ' ')
{
putchar(c);
}
else
{
putchar(nb);
putchar(c);
}
nb=c = getchar();
}
}
方法很笨,如果你有较好的方法,教我吧。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c output string input each