void display_grid(struct game_board *M, FILE *stream) {
int i, j;
/* malloc memory for appropriate amount of rows */
M->border = malloc(sizeof(*M->border) * (M->width + 4));
for (i = 0; i <= M->width; i+=2){
M->border[i] = M->border[M->width + 1] = '+';
for (j = 1; j <= M->width; j+=2){
M->border[j] = M->border[M->width] = ' ';
fprintf(stream, "%c\n", M->border[i][j]);
}
}
M->border[M->width + 2] = '\0';
fflush(stream);
}
My question is in regards to this line fprintf(stream, "%c\n", M->border[i][j]); which shoots an error and stops the overall program from compiling.
At the moment I am simply trying to read in the height and width from what the user is providing from the command line and using that to print out a 2D grid that I can then use later on to modify and such.
I have a solution which I THINK might fix it but I have no idea on how to implement it. I believe that in order to fix the problem I need to malloc border as a ** and then malloc the rows as *
borderhave? It looks as if you construct it withwidth+4, but try to read it as if it werewidth(width+1). - Betachar **ais no 2D array! Setup and usage is more complicated than using a proper 2D array. I agree with @Beta. You really should first learn to walk before starting to run. - too honest for this site