2D array question
v8902477 at cc.nu.oz.au
v8902477 at cc.nu.oz.au
Mon Jul 2 12:57:22 AEST 1990
Hello, could somebody please help me with the following? I'm attempting
to create a two dimensional array at run time using calloc. The array is an
array of structures like this :
struct a {
int a1, a2, a3;
};
And I'm using :
array = (struct a *) calloc(xdim*ydim, sizeof(struct a));
to allocate space for the array. xdim and ydim are the dimensions. I believe
this correct. It seems to work. The problem came when I attempted to assign a
value to an element in the array. I tried it this way :
*((array+x+y*ydim).a1) = value;
Am I correct with this? If array is a pointer it's okay to add integers to it
and use the sum as a pointer, is it not? I get an error stating that .a1 is not
a valid lvalue. Should I be using -> somewhere?
Help please!
Bernard.
Sorry if this has been asked before.
More information about the Comp.lang.c
mailing list