PDA

Click to See Complete Forum and Search --> : refering to a location in a two dim array


bob323
Mar 17th, 2001, 05:04 PM
I have a two dim array that I created using pointers:

int row;
int **temp;

temp = (int **) calloc (10, sizeof(int));

for (row=0; row <10; ++row)
temp[row] = (int *) calloc (10, sizeof (int));


but I need to use a pointer in this last line instead of temp[row] any idea how?

parksie
Mar 17th, 2001, 05:15 PM
Use (*(temp + (row * sizeof(temp[0]))). One other thing though, you need to make sure that you're using proper sizes, so your first call to calloc should be:

temp = (int **)calloc(10, sizeof(int*));

...since it's a pointer.