This example works but I think that the memory leaks. Function used in the simple web server module and thus shared memory grows if you use this function.
This will replace all occurrence of "str" with "rep" in "src"...
void strreplace(char *src, char *str, char *rep)
{
char *p = strstr(src, str);
do
{
if(p)
{
char buf[1024];
memset(buf,'\0',strlen(buf));
if(src == p)
{
strcpy(buf,rep);
strcat(buf,p+strlen(str));
}
else
{
strncpy(buf,src,strlen(src) - strlen(p));
strcat(buf,rep);
strcat(buf,p+strlen(str));
}
memset(src,'\0',strlen(src));
strcpy(src,buf);
}
}while(p && (p = strstr(src, str)));
}