I'm having difficulty initializing a struct in code per below. Can this even be done, or do I really need to memcpy (urg) the 5-character string into the struct?
struct MyStruct
{
char x[5];
};
main(...)
{
const char* MyString = {"mnopq"}; // I understand this is a non-NULL terminated string -
// it's OK, I just want five character fields in an array
struct MyStruct = {MyString}; // <---This gives warnings below
}
warning: missing braces around initializer
warning: initialization makes integer from pointer without cast
If I wrap initializer like:
struct MyStruct = {{MyString}};
the first warning goes away. The second warning does not. And, thus, the struct is not initialized as hoped.
Thanks in advance for help.
const char* MyString = "mnopq", then it is a null-terminated string. Yet, in the code comments you say that it is not. ??? Decide what you want and edit your question. At this time it is a mess.