我無法真正理解自由進程返回錯誤的原因。我得到這個代碼在C:未能釋放內存
int LuffarschackStart(void)
{
/* to avoid the program from closing */
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;
}
董事會結構,我很分配如下所示:
typedef struct
{
/* flag to indicate if a square is free or not */
int free;
/* the type of piece stored on the square if the
square is not free, in this case the admissible
values are CROSS_PIECE and CIRCLE_PIECE,
otherwise the value NO_PIECE is used */
int piece_type;
} square_type;
typedef struct
{
square_type square[N_SQUARES];
int computer_type;
int player_type;
} board_type;
可能的問題是,我需要釋放第一板裏面的square_type?如果是這樣的話,我該如何解脫?
請注意,你的抽象可能是錯的。它不是板子,它是一條條。考慮平方[N_BOARDSIZE,N_BOARDSIZE] – 2010-02-13 21:11:07