I have been trying to remove characters from a string without using extra memory and soing it in place. I just tried removing character 'a' from a given input string but my code gives a segmentation fault .
Input- abca
Output-bc Debugger says the segmentation error is in line "str[j]=str[i]". Please help me out :) Thanks
Here is the code
#include<stdio.h>
#include<string.h>
void removest(char *str)
{
int i,j=0;
int len=strlen(str);
for(i=0;i<len;i++)
{
if(str[i]=='a')
{
i=i+1;
}
str[j]=str[i];
j++;
}
str[j]='\0';
printf("%s \n",str);
}
int main()
{
char *str="abca";
removest(str);
}