Assigning a dynamically allocated 2-d array to a double pointer within a struct : I am creating a game with a 2d array as the board. Originally, I tried to dynamically allocate the board to the struct in one function, but figured I would create the board, and then assign this newly created board to the double point within the struct.

    
    typedef struct Game_State{
    int num_rows;
    int num_cols;
    int num_mines;
    char** board;
    char MINE;
    char hidden_tile;
    char marked_tile;
    char flagged_tile;
    char revealed_tile;
    }game;

This is my delcaration of the struct, Now when I run my create board function, everything works out, but when I print to it there is a seg fault, so I am going to assume I haven't allocated enough space and there is an issue with my pointers. 

    void create_board(struct Game_State game){
    //intitialization
    int i;
    int j;
    int num_rows = game.num_rows;
    int num_cols = game.num_cols;
    char  hidden_tile = game.hidden_tile;
    char **board = game.board;
    printf("Create Board Rows: %d\n", num_rows);
    printf("Create Board Cols: %d\n", num_cols);
    printf("Create Board Hidden Tile: %c\n", hidden_tile);
    //dynamically allocates space for the board (2x2)
    board = (char**)malloc(num_rows *sizeof(char*));
    for(i = 0; i < num_rows; ++i){//for each row
        board[i] = (char*) malloc(num_cols * sizeof(char));
        for(j = 0; j < num_cols; ++j){
            board[i][j] = hidden_tile;
        }
    }
    
}

This is the code I used to create a dynamically allocated board depending on the command line arguments of rows and columns, yet when I print the board, there is a seg fault! Please help! 



    

                                             

          

