I think you are confusing the terminology, you can initialize a pointer to char(acter) like this:
char *literal = "asdf\r\n"
Amendment: However, C Strings are capable of using escape quotes for example:
char *literal = "\basdf\x1b\r\n\v\t";
That will print out
<backspace>asdf<escape-character><carriage-return><linefeed><vertical-tab><tab>
Those characters will not be shown depending on the console capabilities, you may see an arrow for the escape, and a spacing for the tab... you can get around this by using a simple logic, for every \
encountered, insert another \
such that it will display
asdf\\r\\n
something like the following code should suffice:
void ToLiteral(const char *pStr){
char *p = (char*)pStr;
while (*p){
/* if (*p == '\\') putchar('\\'); */
/* PERFORM THE LOOK UP */
putchar(*p++);
}
}
But looking at it, it did not feel right as the pointer was holding the actual \n
and \r
so it might be easier to use a look-up table that compares the actual hexadecimal code for the escape sequences and to display the appropriate code... the lookup table could be something like this
struct LookUp{
int codeLiteral;
char *equivCodeLiteral;
};
struct LookUp look[] = { { 0xa, "\\r"}, { 0xd, "\\n" }, { 0x9, "\\t" } };