I have written the following replace function which replaces substring inside a big string as follows:
void replace(char *str1, char *str2, int start, int end)
{
int i,j=0;
for(i=start; i<end; i++, j++)
*(str1+i)=*(str2+j);
}
It works fine when I put a string as replace("Move a mountain", "card", 0,4), but when I declare a string using pointer array like char *list[1]={"Move a mountain"} and pass it to the function as replace(list[0], "card",0,4), it gives me a segmentation fault.
Not able to figure it out. Can anybody please explain this to me?