Edit: After asking this question I was informed about the question How to initialize a char array without the null terminator? which is almost identical. (I'm building a network packet as well.)
I'll keep this question open anyway, because I'm just assigning and not initializing.
I have a fixed size array that I would like to assign a fixed text to:
char text[16]; text = "0123456789abcdef"; Of course this doesn't work because the right hand side contains the null terminator.
error: incompatible types in assignment of 'const char [17]' to 'char [16]' The text is human-readable, so I would prefer to keep it in one piece, i.e. not write {'0', '1', ...}.
Can I make the assignment work somehow?
By the way, I only have a few hundred bytes of RAM, so preferably (but second to the human-readability requirement) the solution shouldn't use twice the RAM for a temporary copy or something like that.
strcpy(text, "0123456789abcde"); /* text has space for 15 "real" characters and the zero terminator */Note thatstrcpy(text, "0123456789abcdef");is an error!char text[] = "0123456789abcdef";char text[16] = "0123456789abcdef";(note that won't work in C++)