I have a string in my program containing a newline character:
char const *str = "Hello\nWorld";
Normally when printing such a string to stdout the \n creates a new line, so the output is:
Hello
World
But I would like to print the string to stdout with the newline character escaped, so the output looks like:
Hello\nWorld
How can I do this without modifying the string literal?