I cannot understand why the free process returns with an error. I got this code in C:
int LuffarschackStart(void)
{
char readEnd;
int i = 0;
board_type *board = malloc(sizeof(square_type));
if (board == NULL)
{
printf("Could not allocate the memory needed...");
scanf("%c", &readEnd);
return 0;
}
for(i = 0; i < 9; i = i + 1)
board->square[i].piece_type = NO_PIECE;
board_play_game(board);
free(board);
printf("Press any key and enter to quit the program...");
scanf("%c", &readEnd);
return 0;
}
The structure of the board that I distribute looks like this:
typedef struct
{
int free;
int piece_type;
} square_type;
typedef struct
{
square_type square[N_SQUARES];
int computer_type;
int player_type;
} board_type;
Could the problem be that I need to free square_type inside the board first? If so, how should I free it?
source
share