could somedoby clarify some basic C language moments.
struct key {
char *name;
int value;
};
struct key first_key_array[] = {
{"abc", 5},
{"xyz", 6},
{"def", 7}
};
struct key second_key_array[] = {
{"what", 200},
{"when", 300}
};
struct data {
struct key **key_array;
};
struct data all_key_arrays[] = {
{first_key_array},
{second_key_array}
};
I could directly access first_key_array[0]:
printf("%s %d", first_key_array[0].name, first_key_array[0].value);
But access via all_key_arrays does not work:
printf("%s %d", all_key_arrays[0].key_array[0].name, all_key_arrays[0].key_array[0].value);
Could somebody share any ideas?
struct data all_key_arrays[] =is ill-formed. Your compiler should tell you about this. If you don't see any compiler messages then you need to figure out how to stop disabling your compiler's output messages . You need to fix the compiler messages before trying to run the program.struct key **key_array;should bestruct key *key_array;, although this design has a problem that if you go in viaall_key_arraysthen there is no way of checking you don't access past the end of wherever it is pointing