All pastes #229765 Raw Edit

bet0x

public c v1 · immutable
#229765 ·published 2006-10-30 22:37 UTC
rendered paste body
static void str_replace(char *str, const char *from, const char *to, int maxlen){  char  *pstr   = str;  int   fromlen = strlen(from);  int   tolen   = strlen(to);    while (*pstr != '\0' && pstr - str < maxlen) {    if (strncmp(pstr, from, fromlen) != 0) {      *pstr++;      continue;    }    memmove(pstr + tolen, pstr + fromlen, maxlen - ((pstr + tolen) - str) - 1);    memcpy(pstr, to, tolen);    pstr += tolen;  }}