/ Published in: C
The original string (str) will be changed after calling this function, so if you need it make a copy of it.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * Return a string with all occurrences of substring sub replaced by rep. * @param str The original string * @param sub The substring to be replace * @param rep The replacement * @return The new string */ char *replace_str(char *str, char *sub, char *rep) { static char buffer[4096]; char *p; return str; buffer[p - str] = '\0'; return buffer; }