Don't use recursion in this case, this function is suited for looping.
since you are using char and I don't see C++ syntax, you can as well Google for
C string replace
The first link in Googke:
What is the function to replace string in C? - Stack Overflow[
^] contain this code as first answer.
char *str_replace(char *orig, char *rep, char *with) {
char *result; char *ins; char *tmp; int len_rep; int len_with; int len_front; int count;
if (!orig)
return NULL;
if (!rep)
rep = "";
len_rep = strlen(rep);
if (!with)
with = "";
len_with = strlen(with);
ins = orig;
for (count = 0; tmp = strstr(ins, rep); ++count) {
ins = tmp + len_rep;
}
tmp = result = malloc(strlen(orig) + (len_with - len_rep) * count + 1);
if (!result)
return NULL;
while (count--) {
ins = strstr(orig, rep);
len_front = ins - orig;
tmp = strncpy(tmp, orig, len_front) + len_front;
tmp = strcpy(tmp, with) + len_with;
orig += len_front + len_rep; }
strcpy(tmp, orig);
return result;
}