I'm trying to implement a function for removing a substring from a string with memmove. When printing out the results, it seems like I have not moved correctly the substrings, even though it seems like I used the correct position in the source string. My function is:
char * removeSubStr(char * str, const char * substr){
char *scan_p, *temp_p;
int subStrSize = strlen(substr);
if (str == NULL){
return 0;
}
else if (substr == NULL){
return str;
}
else if (strlen(substr)> strlen(str)){
return str;
}
temp_p = str;
while(scan_p = strstr(temp_p,substr)){
temp_p = scan_p + subStrSize;
memmove(scan_p, temp_p, sizeof(temp_p)+1);
}
return str;
}
My output, for example is: if sending the string "please remove rem remove rem999", I'm getting back: "please ove rm ovmove re 999"
Thanks!