I am trying to initialize a char array with a long string. However, I do not want it to be NULL terminated.
This:
const char s[] = "The actual string is much longer then this...";
is much easier to read (and to write) than this:
const char s[] = {'T', 'h', 'e', ' ', 'a', 'c', 't', 'u', 'a', 'l', ' ', 's', ...};
but the former gets NULL terminated. Is there a way to avoid the NULL on a string literal?
The reason for doing this is that there is the need to pack densely strings in memory of fixed size length known during development.
No.
A string literal is a C-string which, by definition, is null-terminated.
Either ignore the final character, revisit your requirements (why do you care about a final character?!) or … I dunno, something else. Perhaps generate the objects with xxd?
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