I have an array that looks like this:
struct table_elt
{
int id;
char name[];
}
struct table_elt map[] =
{
{123,"elementt1"},
{234,"elt2"},
{345,"elt3"}
};
I'm trying to access these elements through map[1].name, etc. However, it doesn't seem to be able to fetch the elements correctly, and I get random junk. I think this is because the compiler doesn't know where the elements will land up due to varying. What's the best way to fix this, while still maintaining as much flexibility and simplicity?
You probably want :
struct table_elt
{
int id;
const char *name;
}
struct table_elt map[] =
{
{123,"elementt1"},
{234,"elt2"},
{345,"elt3"}
};
On a side note, table_elt
doesn't even need a name if it's used in this context only.
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