Posted By: Fenriswolf
Dynamically allocated struct array - 04/01/08 09:43
Hello,
I have some problems using a dynamically allocated struct array that I hope someone could help me out with.
The following line causes an error while compiling:
thingy.array[0] ...
The error reads:
Thanks
I have some problems using a dynamically allocated struct array that I hope someone could help me out with.
Code:
typedef struct THINGY { /* should point to an array of STUFF */ STUFF *array; }THINGY; [...] THINGY *thingy = malloc(sizeof(THINGY)); /* allocates an array of length 100 */ thingy.array = (STUFF *)malloc(100 * sizeof(STUFF)); /* and this causes an compiler error: "subscript requires array or pointer type" */ thingy.array[0] = NULL;
The following line causes an error while compiling:
thingy.array[0] ...
The error reads:
Quote:
subscript requires array or pointer type
Thanks