EDIT -- can the down voter explain? I have a clear question, with supporting evidence, and proof of prior investigation. I would like to understand why you are down voting me...?
I am getting this error when I compile with gcc:
error: incompatible types when assigning to type ‘struct cell’ from type ‘void *
The problem lines are:
struct cell* cells = NULL;
cells = malloc(sizeof(struct cell) * length);
for (i = 0; i < length; i++) {
cells[i] = malloc(sizeof(struct cell) * width);
I believe I have followed the proper protocol, as described here and also here. What am I missing?
For a multidimensional array, you want an array of type struct cell** cells
:
struct cell** cells = NULL;
cells = malloc(sizeof(struct cell*) * length);
for(int i = 0; i < length; i++) {
cells[i] = malloc(sizeof(struct cell)*width);
}
Now cells
is a multidimensional array, where the first index range is the length and the second index range is the width.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With