Input- Hello World
output- HelloWorld
This is program i have written in c.
But i get segmentation fault.
The logic i have used is, when i found a space i swap that with next character till end then insert a '\0' character
#include <stdio.h>
int main()
{
char s[12]="Hello World";
char *t;
t=s;
while(*t)
{
char *p;
p=t;
if(*p==' ')
{
while(*p !='\0')
{
char x;
x=*p;
*p=*(p+1);
*(p+1)=x;
p++;
}
*(p-1)='\0';
}
t++;
}
printf("%s\n",s);
}