In a string literal, how can I follow a hexadecimal escape sequence immediately with a literal character that can be interpreted as a hexadecimal digit? For example, if I write this literal ...
"BlahBlah\x04BlahBlah"
... the 'B'
immediately following the '4'
will be interpreted as part of the hexadecimal escape, because it is a valid hexadecimal digit.
How can I write a string literal that represents the string that the above would represent if the
'4'
were taken as the last character of the hex escape?
As you noticed, C is pretty dumb when it comes to hex escape sequences in string literals. Fix it by using string concatenation, like this:
"BlahBlah\x04" "BlahBlah"
It is good practice to never have any trailing characters behind such a hex escape sequence. Always end the string as in this example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With