Due to the necessity of enclosing strings within quotes, this particular string may lead to misinterpretation by C, resulting in an error.
char txt[] = “We are the so-called “Vikings” from the north.”; |
To circumvent this issue, one solution is to utilize the backslash escape character.
This ( \ ) converts special characters into string characters.
Escape character |
Result |
Description |
\’ |
‘ |
Single quote |
\” |
“ |
Double quote |
\\ |
\ |
Backslash |
The sequence \” within a string inserts a double quote character:
char txt[] = “We are the so-called \”Vikings\” from the north.”; |
The sequence \’ within a string inserts a single quote character:
char txt[] = “It\’s alright.”; |
The sequence \\ within a string inserts a single backslash character:
char txt[] = “The character \\ is called backslash.”; |
Additional commonly used escape characters in C include:
Escape Character |
Result |
\n |
New Line |
\t |
Tab |
\0 |
Null |