Path: utzoo!attcan!uunet!samsung!munnari.oz.au!metro!cluster!nuts!cc.nu.oz.au!v8902477 From: v8902477@cc.nu.oz.au Newsgroups: comp.lang.c Subject: 2D array question Message-ID: <3336.268f44b2@cc.nu.oz.au> Date: 2 Jul 90 02:57:22 GMT Organization: University of Newcastle Lines: 28 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.