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();
}
}
方法很笨,如果你有较好的方法,教我吧。