Hi,
This is my problem. I have a 2-D array called grid that contains either pointers to structures called node, or NULL. The grid size is grid[SIZE][SIZE]. Each one of the struct nodes has various attributes such as location, id, positionX, and positionY. But when I try to print out the values I get an exception error!!
Any ideas anyone??
P.s - I've left out all the usual variable declaration
Code:
typedef struct node node;
node *nodeLocation;
//Initialise all pointer values in grid[][] to NULL
for (x=0; x < (SIZE); x++)
{
for (y=0; y < (SIZE); y++){
grid[x][y] = NULL;
}
}
// populate grid[][] with different node pointers
// POPULATION corresponds to the number of nodes required
for (i=0; i < POPULATION; i++){
nodeLocation = (node*)malloc(sizeof(node));
positionX = (rand() % SIZE);
positionY = (rand() % SIZE);
grid[positionX][positionY] = nodeLocation;
nodeLocation->id = i+1;
nodeLocation->x = positionX;
nodeLocation->y = positionY;
nodeLocation->age = 0;
i++;
}
[\code]
From here it compiles and runs grand.
It's when I try to print out, say, the node at grid[0][0], that I get the application error:
[code]
printf("\n%d\t%d\t%d\t",grid[0][0]->id, grid[0][0]->x, grid[0][0]->y);
[\code]
Any ideas please!!!????
Thanks,
D