PHP like str_replace function in C

This post is part of a series of posts where I want to document a bunch of C functions I use for my projects that I have written, collected and modified over the past few years. One of the functions that I use regularly is a string replacement function like the str_replace in PHP. This function replaces all occurences of a particular substring with a replacement pattern. The code for this was borrowed from here. In the original code, a newly allocated string is returned after all the substrings are replaced. I have modified it so that the replacements are made in place. Continue reading