I am using VS2013. The whole program is C, not C ++.
I can initialize a "string array" like this without a problem:
char titles[4][80] = { "Dad", "Idiot", "Donut Lover", "Fewl" }; // OK!
I have a structure declared as follows:
typedef struct { char name[80]; char titles[4][80]; } Dude;
When I try to initialize the structure as follows:
Dude homer = { .name = "Homer", .titles = { "Dad", "Idiot", "Donut Lover", "Fewl" }
I get "error C2078: too many initializers." This is due to array initialization. If I delete the line .titles = { ...
, the error will disappear. Why am I getting this error? Is there any other way to initialize this type in the structure initializer?
If I changed the structure declaration to look like this:
typedef struct { char name[80]; char *titles[4]; } Dude;
the error disappears. This, however, is not a change I can make. Other parts of the code base require that this structure be exactly 400 bytes in size.
In addition, I fully understand that I could use strcpy
to populate each field, but this does not answer my question.