I am declaring an array of struct this way :
struct struct_name tab1[6] ={ {"1487" ,0.144}, {"148",2.1}, {"45",0.01}, {"12475847",0.52}, {"46",1.4}, {"0",5} };
struct struct_name tab2[7] = { {"1" ,0.9}, {"76",5.1},{"46",0.17},{"4625",0.0},{"46252",1.57},{"12",1.5},{"5",1.2} };
This works fine.
Now I need to make tab1 and tab2 in one array global_tab and still initialize data this way but so far I haven't been able to do so. I tried dynamic allocation like this
global_tab = malloc(2 * sizeof(struct struct_name *));
global_tab[0] = malloc(100 * sizeof(struct struct_name));
global_tab[0] = { {"1487" ,0.144}, {"148",2.1}, {"45",0.01}, {"12475847",0.52}, {"46",1.4}, {"0",5} };
But I get this error
error: expected expression before ‘{’ token
global_tab[0] ={ {"1487" ,0.144}, {"148",2.1}, {"45",0.01}, {"12475847",0.52}, {"46",1.4}, {"0",5} };
I want to be able to do initialize global_tab[0] the same way I did with tab1
global_tab[0] = somethingthenglobal_tab[0] = something elsemeans that the first assignment is pretty much useless. It's like doingint i = 5; i = 6;.