Friday, October 30, 2009

Chp9[D]f Removing two or more spaces in a string

Write a program that replaces two or more consecutive blanks in a string by a single blank. For example, if the input is






void main()
{
char sent[]="Grim return to the planet of apes!!";
int i;

for(i=0;sent[i]!=0;i++)
{

if(sent[i]==32&&sent[i+1]==32)

{

for(;sent[i+1]!=0;i++)
{
sent[i]=sent[i+1];
}

sent[i]='\0';


i=0;


}



}
printf("\n%s",sent);
}

1 comment: