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);

Comments

  1. char *replace(char *st, char *orig, char *repl) {
    static 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;
    }

    ReplyDelete

Post a Comment

Popular posts from this blog