Q:

Debug string replace function in C

I tried to code a function which replace all string s1 to s2, in a given string s.
however, i don't know why my program stop at the line *p=0 in that replace function without any error reported? @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void replace(char * s, char * s1, char * s2) {
    char * p; int l=strlen(s2);
    while ((p=strstr(s,s1))) {
        *p=0;
        p+=l;
        strcat(s,s2);
        strcat(s,p);
    }
}    

int main(void) {    
    char *s=(char *)"cmd=ls+-la&abc=xyz";
    replace (s, "+", " ");    
    printf("%s", s);
    return EXIT_SUCCESS;    
}

A:

There are some problems with the replace function but, first of all, there is a big difference between a pointer to a constant char array vs a character array:
char *str = "some string";

Assigns str the address of the immutable character array (read-only), it does not copy the string, only pointers are involved. Any attempt to modify that string will result in undefined behavior.
char str[] = "some string";

In this case str is an array (of size big enough to hold the string + \0) that is initialized to that string, allowing the modification of individual characters within the array.
Back to your replace function.
I will start with the first thing that I saw which is your use of strstr and strcat inside the loop is highly inefficient. Every time you call strstr it starts from the beginning of the string and searches for the first occurrence of the second string all over, the same problem can be seen with strcat which needs to find the null-terminator every time.
Another issue I see is if the replacement string (s2) is longer than the original string (s1) you must shift the entire string to accommodate for the additional characters of the new string. The same issue will occur if the replacement string is shorter.
a basic method to replace a simple char might look like this:
while (*s)
{
    if (*s == c1)
        *s = c2;
    ++s;
}

a little more complex method to replace a string would be:
/* PRECONDITION: strlen(s1) == strlen(s2) */
int l = strlen(s2);

while (*s)
{
    if (!strncmp(s, s1, l))
    {
        memcpy(s, s2, l);
        s += l;
    }
    else
        ++s;
}

