#include <stdio.h>
#include <string.h>
void replaceAll(char *s, const char *fromword, const char *toword) {
char *pos, tmp[100];
int len = strlen(fromword);
int i = 0;
while ((pos = strstr(s, fromword)) != NULL) {
strcpy(tmp, s);
i = pos - s;
s[i] = '\0';
strcat(s, toword);
strcat(s, tmp + i + len);
}
}
int main()
{
char s[128] = "python c cpp csharp pythonpython rust go python";
replaceAll(s, "python", "JAVA");
puts(s);
return 0;
}
/*
run:
JAVA c cpp csharp JAVAJAVA rust go JAVA
*/