#include
using namespace std;
void movex(char input[],int i){
if(input[i]==’\0’){
return;
}
if(input[i]==‘x’){
int j=i+1;
while(input[j]!=’\0’){
input[j-1]=input[j];
j++;
}
j–;
input[j]=‘x’;
movex(input,i);
}
else{
movex(input,i+1);
}
}
int main() {
char input[1000];
cin>>input;
movex(input,0);
cout<<input;
return 0;
}
Segmentation fault (core dumped)
You have taken recursive function to be movex (input,i+1,l) for the case input[i]==‘x’
But consider the case when two or more consecutive x is present.
For ex --> abxxcc in this case we will have to pass the recursive function as movex(jnput,i,l)
I tried that in your code but again it shows segmentation fault
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.