Extract a multidimensional array from an array

Right now I'm going crazy with pointers to C. I have the following two multidimensional arrays:

int num0[5][3] = { {0,1,0}, {1,0,1}, {0,1,0}, {1,0,1}, {0,1,0} }; int num1[5][3] = { {1,1,1}, {1,0,1}, {0,1,1}, {0,1,0}, {1,0,0} }; 

Then they are packed into another array as such:

 int (*numbers[])[3] = { num0, num1 }; 

If I then do:

 printf( "Result: %d\n", numbers[0][2][2] ); 

I get the expected result, in this case Result: 1.

However, I would like to assign the numbers [0] to another variable. So, in a modern programming language, you would do something simple:

 int newvar[5][3] = numbers[0]; printf( "Result: %d\n", newvar[2][2] ); 

Although my pointer knowledge is limited, I know that this will not work (and this, of course, is not). But for life, I cannot understand the correct syntax to make it work (and, more importantly, understand WHY it works).

If anyone can help me here, I would really appreciate it!

thanks

+4
source share
1 answer

You cannot assign arrays in C, use memcpy to copy arrays:

  memcpy(newvar, numbers[0], sizeof newvar); 
+2
source

All Articles