If you want to use a string literal and not add an additional terminator (NUL character), do it like this:
static const char str[4] = "\x1\x5\xa\x15";
When the length of the string string exactly matches the declared length of the character array, the compiler will not add the trailing NUL character.
The following test program:
#include <stdio.h> int main(void) { size_t i; static const char str[4] = "\x1\x5\xa\x15"; printf("str is %zu bytes:\n", sizeof str); for(i = 0; i < sizeof str; ++i) printf("%zu: %02x\n", i, (unsigned int) str[i]); return 0; }
Will print this:
str is 4 bytes: 0: 01 1: 05 2: 0a 3: 15
I donβt understand why you would prefer to use this method rather than a more readable and supported original with hexadecimal numbers separated by commas, but maybe your real string also contains plain print characters or something else.
unwind
source share