Check this (http://codepad.org/KCn8i8iN )
#include <stdio.h>
#include <string.h>
char *replace_str(char *str, char *orig, char *rep)
{
static char buffer[4096];
char *p;
if(!(p = strstr(str, orig)))
return str;
strncpy(buffer, str, p-str);
buffer[p-str] = '\0';
sprintf(buffer+(p-str), "%s%s", rep, p+strlen(orig));
return buffer;
}
int main(void)
{
char *str="Query Home is a good website";
char *str1="good";
char *str2="very good";
puts(replace_str(str, str1, str2));
return 0;
}