Flower
Flower

Reputation: 81

How to access three dimensional array outside the loop

I am using C for my program. I am using Ubuntu 14.04. The following is one of the loops that I use.

for (x=0; x<1024; x++)
{
    for (i=0; i<8; i++)
    {
        for (j=0; j<8; j++)
        {
            arr[x][i][j]=vi[8*i+j+gi];
        }
    }
    gi = gi+(8*8);
}

Here 'vi' is a single dimensional array. Now the array 'arr' has 1024 blocks of size 8x8. Is there a provision to access the blocks as such (with size 8x8) outside the loop for further processing?

Upvotes: 0

Views: 81

Answers (2)

Kainix
Kainix

Reputation: 1216

You can access by arr[i][j][k] where 0<=i<=1023,0<=j<=7 & 0<=k<=7

Upvotes: 1

fluter
fluter

Reputation: 13816

If the x array is defined as something like int x[1024][8][8], which means x is an array of 1024 elements where each element is int[8][8], namely an array of arrays of int. So if you want to get certain element, just use subscription to access it, the same way as access to normal arrays. For example, you use x[0] to access the first 8x8 block of x, x[1023] to access the last block.

Upvotes: 5

Related Questions