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?
const char *.*(str1+i)is exactly equal tostr1[i]. The latter is usually easier to read and understand, as well as little shorter to write. This equivalence is true for all arrays and pointers.char*but the C compiler does not. The OP's problem would not have come up had the C compiler also warned about it.char. In C++ a literal string is an array ofconst char. The array in C can't be modified though so it effectively is read-only, but it's still not an array of constant characters. This is just one of the way C and C++ differs, and why many here don't like the term "C/C++" or using both C and C++ tags for questions.