0

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?

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you so much!!!. I have defined the data type of the 3D array as 'unsigned char'. I have used the following code to access the 8x8 array: for (w=0; w<1024; w++) { printf("%u", arr[w]); }. But I get error like, "format ‘%u’ expects argument of type ‘unsigned int’, but argument 2 has type ‘unsigned char". How can I print and preview all the blocks?
Is it defined as unsigned char x[1024][8][8]? By print and preview do you mean print each of the unsigned char?
Yes it is defined as unsigned char x[1024][8][8]. I just want to print all 1024 blocks as 8x8 blocks.
Since each block is 8x8 uchar that's 64 bytes, you can't use %u to print it.
You can print each uchar in a loop
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.