I used malloc to define an index because each line had a different number of elements (simplified example below):
int** Index=malloc(2*sizeof(int*));
Index[0]=malloc(2*sizeof(int));
Index[1]=malloc(3*sizeof(int));
But I did not want to write each element one by one (as follows) because it takes a lot of space and time:
Index[0][0]=1000;
Index[0][1]=1300;
Index[1][0]=1500;
Index[1][1]=2000;
Index[1][2]=2900;
But rather wanted to use a way to do it in a single line of code as follows:
Index[0]={1000,1300};
Index[1]={1500,2000,2900};
As I've been taught to do on "regular" indexes. Only problem is that my compiler doesn't seem to like such notations with an index defined with the help of a malloc. Is there another way rather than to write dozens of lines of code?
I searched for a similar question on this website but was unable to find one.
memcpyand compound literals (@ikegami), you could write a macro to streamline this approach, you could use astructwith array members, you could write data in a file and read it into memory at runtime,....int a; ... a = b;, thea = b;is an assignment, not an initialization, even if is the first assignment.