finds a substring in a string and replaces
Write a function which finds a substring in a string and replaces all occurrences with another string.
Prototype of the function :
char* FindReplace(char* src, char* find, char* replace);
Prototype of the function :
char* FindReplace(char* src, char* find, char* replace);
char *replace(char *st, char *orig, char *repl) {
ReplyDeletestatic char buffer[4096];
char *ch;
if (!(ch = strstr(st, orig)))
return st;
strncpy(buffer, st, ch-st);
buffer[ch-st] = 0;
sprintf(buffer+(ch-st), "%s%s", repl, ch+strlen(orig));
return buffer;
}