I'm trying to construct a little simulation in which I have a 2D World populated by Agents. I'm trying to construct this world as a 2D array of pointers to Agent structs. If no agent is present on a given grid element, that element contains NULL.
Here is my World typedef:
Code:
#include "agent.h"
#define WIDTH 100
#define HEIGHT 100
typedef struct _World
{
Agent* world[WIDTH][HEIGHT];
}World;
Agent is another typedef struct.
I'm doing something or conceptualizing something wrong because when I attempt to compile my code for my World constructor, I get the following error message when I attempt to assign an element of the array to NULL:
subscripted value is neither an array nor pointer
I'm confused because my World typedef seems to declare a 2D array of pointers.
Here is my constructor:
Code:
World* world_constructor()
{
World* new_world = malloc(sizeof(World));
int i = 0;
int j = 0;
for(i; i < WIDTH; i++)
{
j = 0;
for(j; j < HEIGHT; j++)
{
new_world[i][j] = NULL;
}
}
return new_world;
}
Thanks for your help.