How do I return the indices of a multidimensional array element in C?

Posted by Eddy on Stack Overflow See other posts from Stack Overflow or by Eddy
Published on 2010-04-09T15:40:20Z Indexed on 2010/04/09 15:43 UTC
Read the original article Hit count: 164

Say I have a 2D array of random boolean ones and zeroes called 'lattice', and I have a 1D array called 'list' which lists the addresses of all the zeroes in the 2D array. This is how the arrays are defined:

define n 100  
bool lattice[n][n];  
bool *list[n*n];

After filling the lattice with ones and zeroes, I store the addresses of the zeroes in list:

for(j = 0; j < n; j++)
{   
    for(i = 0; i < n; i++)
    {
        if(!lattice[i][j])  // if element = 0
        {
            list[site_num] = &lattice[i][j];  // store address of zero
            site_num++;
        }
    }
}

How do I extract the x,y coordinates of each zero in the array? In other words, is there a way to return the indices of an array element through referring to its address?

© Stack Overflow or respective owner

Related posts about arrays

Related posts about c