我创建了一个二维数组,但失败了,我得到“lab10.exe 中 0x77a415de 处的未处理异常:0xC0000374:堆已损坏。” 不知道从这里去哪里或如何调试。我相信这与我的数组大小或使用 malloc() 有关。非常感谢您提前提供的帮助!
//Get the number of Columns from the user
printf("Enter the number of rows and columns:\n");
scanf("%d", &dimension);
//Allocate 1-D Array of Pointers, Array 'a'
a = (int** ) malloc( sizeof(int)*dimension);
if(a == NULL)
{
printf("\nError Allocating Memory");
exit(1);
}
//Allocate Rows for 2-D Array; Array 'a'
for(r = 0; r < dimension; r++)
{
a[r] = (int*) malloc( sizeof(int) * dimension);
if (a[r] == NULL)
{
for(i = 0; i< r; i++)
free(a[i]);
printf("\nError Allocating Memory");
exit(1);
}
}
还有更多,但我从相同的整数“维度”执行了 4 次不同的操作。谢谢!