可能重複:
How do I correctly set up, access, and free a multidimensional array in C?2D陣列動態存儲器分配崩潰
我試圖動態地分配存儲器使用釋放calloc 2D陣列。列固定爲2,因此它只有動態的行。
這是我一直在努力:
unsigned int **pts, rows;
int main()
{
//some code
pts = (unsigned int **)calloc(2*rows, sizeof (unsigned int **));
}
//The code to access the array :
for(k=1;k<=i;k++)
{
printf("\nX%d=",k);
scanf("%d",&pts[k][0]);
printf("\nY%d=",k);
scanf("%d",&pts[k][1]);
}
但問題是,在訪問陣列,程序崩潰。 我在MinGW GCC中使用Eclipse。
請讓我知道如果我需要在這裏提供更多的數據或給我一些想法我可以如何處理這個,因爲這是我的第一篇文章。
[我如何在C中正確設置,訪問和釋放多維數組?](http://stackoverflow.com/questions/12462615/how-do-i-correctly-set-up-access-and -free -a-multidimensional-array-in-c) – Lundin
你可以在你訪問數組的地方發佈代碼嗎? – CCoder