im working on a function that will remove a string from a string. so if i run
char tmp[] = "testing a not working idea. not not not";
removeallstrings(tmp, "not");
tmp should be changed to "testing a working idea". i can get a function to pass threw once, but it wont return a value so a while loop can stop.
here what i have
Code:int removestring(char *src, char string[]) {
char *start = strstr(src, string);
char *end = NULL;
if(start != NULL) {
end = &src[(strlen(src) - strlen(start) + strlen(string) + 1)];
*start = '\0';
strcat(src, end);
} else
return 1;
return 0;
}
int removeallstrings(char *src, char string[]) {
while( removestring(src, string) == 0 )
;;
return 0;
}
int main() {
char tmp[] = "testing a not working idea. not not not";
removeallstrings(tmp, "not");
printf("%s\n", tmp);
return 0;
}