I would like to replace the characters \n, \r and \f whenever I encounter them in a string with <br>. To replace a single character, in the string, I could use the following code:
.
.
.
{
char oldc, newc, *cp;
char *s = "Hello World. Hello World";
oldc = '\n';
cp = s;
while ((cp = strchr(sp, oldc)) != NULL)
*cp = newc;
}
However, in this case, I want to replace 4 characters in place of the \n, \r or \f, i.e. <br>. I wonder if I have to use another string and copy the contents from the first string to the second string and replacing the \ characters with <br>.
If anyone can show me a simple and effective way to do this, I would really appreciate it.
Start Free Trial