printf("Size of the board in bytes %d\n", sizeof(boardSize)); printf("Size of column size in bytes %d\n", 5*sizeof(int)); printf("Size of row in bytes %d\n", 5*sizeof(int));
If you want to leave the board as statically allocated, declare it global,
static int board[5][5];
Then move it to your createBoard method (I hate Hungarian notation) for proper initialization:
for(i = 0; i < hight; i++) for(j = 0;j< width; j++) board[i][j] = <initialization stuff>
or you can dynamically distribute it in your createBoard () method. In this case, do not declare the local variable main.
int * createBoard(int hight, int width){ int * board; if(board = malloc(sizeof(int) * hight * width)) return board; return NULL; }
in main () you can do something like this:
int * board = createBoard(5,5); if(!board) printf("Allocation failure \n"); exit(EXIT_FAILURE);
source share