I created a function to do that, and I want to know if there is a problem I'm overlooking about it ..
void replaceStr(buffer, haystack, needle, rep)
char *buffer, *needle, *rep;
const char *haystack;
{
if (!buffer || !haystack || !needle || !rep)
return;
size_t rep_length = strlen(rep);
long long diff = strlen(needle) - rep_length;
memcpy(buffer, haystack, strlen(haystack) + 1);
while ((buffer = strstr(buffer, needle))) {
memcpy(buffer, rep, rep_length + 1); /* +1 for the null byte */
if (diff > 0) {
long long i;
for (i = diff; i <= diff; ++i)
buffer[i] = buffer[i+1];
buffer[i] = 0;
}
}
}