It struck me later that the code is not very optimal, because it continuously rescans the string. Also, if you feed it this:
Code:
char eg[]= "hellolowworld";
removeSubstr(eg, "low");
You'd end up with "helorld", which might not be what you want. So a better version is:
Code:
void removeSubstr (char *string, char *sub) {
char *match = string;
int len = strlen(sub);
while ((match = strstr(match, sub))) {
*match = '\0';
strcat(string, match+len);
match++;
}
}
Which does not repeatedly re-scan, and thereby also misses the helorld pitfall.