所以我有一个代码,当我运行它,它,当我进入一个大小大于3。当它的正是3运行平稳挂起。 我缩小了问题malloc和free,我不知道是什么问题。 我在这是新所以任何帮助表示赞赏。
do //repeatedly ask the user to put a number between 3-9
{
printf("Enter the size of the game board between 3-9: ");
scanf("%d", &size);
}while(size<3 || size>9);
if((board = (char***)malloc(sizeof(char**)*size))==NULL)
printf("Memory Allocation failed\n");
for(i=0; i<size; i++)
{
if((board[i] = (char**)malloc(sizeof(char*)*size))==NULL)
printf("Memory Allocation failed\n");
for(j=0; j<size; j++)
{
if((board[i][j] = (char *)malloc(sizeof(char)*4))==NULL)
printf("Memory Allocation failed\n");
strcpy(board[i][j], "Go");
}
}
/*************Some random code ***********/
free(board);
for(i=0;i<size;i++)
{
free(board[i]);
for(j=0;j<size;j++)
free(board[i][j]);
}