Tuesday, May 01, 2012

C Program That Replace Double Space With Single Space In The Given String.

Friends in this program i inputed a string with single and double spaces and after that remove all the double spaces with single space. for example if you enter a string "hello  guys enjoy  this program" then output should be"hello guys enjoy this program" you can see that all the double spaces has been removed.


#include<stdio.h>
#include<conio.h>
int main()
{
 char str[100];
 int i,c=0,j;
 clrscr();
 printf("\n Enter the string with single and double spaces:\n");
 gets(str);
 for(i=0;str[i]!='\0';i++)
 {
  if(str[i]==' '&&str[i+1]==' ')
  {
   str[i]=' ';
   for(j=i+1;str[j]!='\0';j++)
   {
    str[j]=str[j+1];
   }
  }

 }
 puts(str);
 getch();
 return(0);
}



                    Thanking You Friends...........

No comments:

Post a Comment

Please Give Me Your Views

Popular Posts