Reputation: 51
I need to prepare constant array of ANSI C strings that contains bytes from range of 0x01
to 0x1a
. I made custom codepage, so those values represents different characters (i.e. 0x09
represents Š). I'd like to initialise the array in that way:
static const char* brands[] = {
"Škoda",
//etc...
};
How can I put 0x09
instead of Š
in "Škoda"
?
Upvotes: 1
Views: 267
Reputation: 153650
Recommend not using "\x09koda"
, use octal or spaced strings.
The problem is that hexadecimal escape sequences are not limited in their length. So if the next char
is a hexadecimal character, problems occur. Use octal, which is limited to 3. Or use separated strings. The compiler will concatenate then, but the escape sequence will not accidentally run too far.
// problematic
"\x09Czech"
^^^^^--- The escape sequence is \x09C, but \0x09 was hoped for
// recommend octal
"\0111234"
^^^^--- The escape sequence is \011
// recommend spaced strings
"\x09" "Czech"
Upvotes: 6
Reputation: 9752
Have a look at escape squences - i.e \x09
For hex escape you want to use the \Xnnn
, for octal just \nnn
and for unicode \Unnnn
Upvotes: 1