fix replacing ignorecase with multiple things to replace

This commit is contained in:
Joshix 2021-10-03 12:36:08 +02:00
parent ae793ea029
commit f1ef095a9c

View file

@ -708,11 +708,12 @@ replace("Hello World!", "World", "everyone")
*/
void replace(char *original, char *search, char *replacer)
{
char buffer[1024];
char *ch;
if (!(ch = strstr(original, search)))
return;
char buffer[1024];
strncpy(buffer, original, ch - original);
buffer[ch - original] = 0;
sprintf(buffer + (ch - original), "%s%s", replacer, ch + strlen(search));
@ -724,18 +725,20 @@ void replace(char *original, char *search, char *replacer)
void replace_ignorecase(char *original, char *search, char *replacer)
{
char buffer[1024];
char *ch;
if (!(ch = strcasestr(original, search)))
return;
char buffer[1024];
strncpy(buffer, original, ch - original);
buffer[ch - original] = 0;
sprintf(buffer + (ch - original), "%s%s", replacer, ch + strlen(search));
original[0] = 0;
strcpy(original, buffer);
return replace(original, search, replacer);
replace(original, search, replacer);
return replace_ignorecase(original, search, replacer);
}
void print_ascii()