There are two problems with the function.
First of all this statement
Game *thegame = (Game *)malloc(sizeof(Game*));
allocates memory with the size equal to the size of the pointer Game* instead of allocating memory with the size equal to the size of the structure Game or struct game_t that is the same.
You have to write
Game *thegame = (Game *)malloc(sizeof(Game));
or
Game *thegame = (Game *)malloc(sizeof(struct game_t));
The second problem is that there can be a memory leak in case when the variable historySize is less than or equal to 0.
Take into account that it is better to specify the function parameter as void.
The function definition can look the following way
Game * Create( void )
{
Game *thegame = NULL;
if ( historySize > 0 && ( thegame = malloc( sizeof( Game ) ) ) != NULL )
{
for ( int row = 0; row < ROWS; row++ )
{
for ( int col = 0; col < COLUMNS; col++ )
{
thegame->gameBoard[row][col] = EMPTY_ENTRY;
}
}
}
return thegame;
}
Also it is not a good idea when a function deals with global variables. You could pass the variable historySize as an argument to the function.
In this case the function will look like (I suppose that the type of the variable historySize is int)
Game * Create( int historySize )
{
Game *thegame = NULL;
if ( historySize > 0 && ( thegame = malloc( sizeof( Game ) ) ) != NULL )
{
for ( int row = 0; row < ROWS; row++ )
{
for ( int col = 0; col < COLUMNS; col++ )
{
thegame->gameBoard[row][col] = EMPTY_ENTRY;
}
}
}
return thegame;
}
In this case the function can be called like
Create( historySize );
There is a possibility to substitute the loops for a call of the standard function memset.
For example
#include <string.h>
//...
Game * Create( int historySize )
{
Game *thegame = NULL;
if ( historySize > 0 && ( thegame = malloc( sizeof( Game ) ) ) != NULL )
{
memset( thegame->gameBoard, EMPTY_ENTRY, ROWS * COLUMNS );
}
return thegame;
}