samedi 18 avril 2015

Declaring a 2D array in a struct without knowing the size in a struct?


Vote count:

0




Can I do this in C?


I have this code that gives me the error



ERROR
minesweeper.c:19:19: error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ before ‘=’ token
int *boardSpaces = (int *)malloc(newBoard.rows * newBoard.columns * sizeof(int));

typedef struct boards
{
int rows, columns;
int *boardSpaces = malloc(rows * columns * sizeof(int));
} Board;


But when I put it in my main it works just fine.


Can I declare this in a struct, or is it just I am missing something?



asked 52 secs ago







Declaring a 2D array in a struct without knowing the size in a struct?

Aucun commentaire:

Enregistrer un commentaire