Possible Duplicate:
How do I correctly set up, access, and free a multidimensional array in C?
I am trying to dynamically allocate memory for a 2D array using calloc. The columns are fixed as 2 so its only the rows that are dynamic.
Here is what I have been trying :
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]);
}
But the problem is, while accessing the array, the program crashes. I am using Eclipse with MinGW GCC.
Please let me know if I need to put more data here or give me some idea how I can deal with this, as this is my first post.