so i need to create a function that creates a 2 dimensional field of pointers to a structure called a "cell".
this is the code for the structure, nothing too hard here
Code:
#ifndef CELL_H_
#define CELL_H_
/*
* Dit zijn de twee groepen die er bestaan in de variant op Conway's Game of Life die jullie moeten implementeren.
* Een cel behoort altijd tot een van deze twee groepen.
*/
enum Group {
A, B
};
/*
* Dit zijn de mogelijke staten waarin elke cel zich bevindt: een cel is altijd ofwel dood ofwel levend.
*/
enum State {
ALIVE, DEAD
};
/*
* Een cel wordt voorgesteld als een struct die tot een bepaalde groep hoort (groep A of groep B)
* en een bepaalde staat heeft (levend of dood).
*/
struct Cell {
enum Group group;
enum State state;
};
#endif /* CELL_H_ */
and here is the code for the function that allocates a pointer to a "cell" structure and where every cell is initialized to the state "DEAD". (its an implementation of conways game of life). the error appears on line 26 which is
Code:
cell_pointer->state = 1;
full code :
Code:
#include <stdlib.h>
#include <stdio.h>
struct Cell ***allocate_field(int field_width, int field_height){
//creer geheugen voor het aanmaken van de nodige vectoren van pointers
struct Cell*** kolommen = malloc(field_width * sizeof *kolommen);
int i;
int j;
for(i=1;i == field_width;i++){
kolommen[i] = malloc(field_width * sizeof (struct Cell**));
for(j=1;j == field_height;j++){
struct Cell *cell_pointer;
kolommen[i][j] = malloc( sizeof (struct Cell*));
kolommen[i][j] = cell_pointer;
cell_pointer->state = 1;
}
}
return kolommen;
}