c - Retrieving a multidimensional array from an array -
i'm going crazy pointers in c @ moment. have following 2 multi-dimensional 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} };
these packed array such:
int (*numbers[])[3] = { num0, num1 };
if do:
printf( "result: %d\n", numbers[0][2][2] );
i expected result, in case result: 1.
however, i'd assign numbers[0] variable. in modern programming language, you'd simple as:
int newvar[5][3] = numbers[0]; printf( "result: %d\n", newvar[2][2] );
even though pointer knowledge limited, know isn't going work (and of course doesn't). life of me can't figure out correct syntax make work (and more importantly, understand why works).
if out there can me out here i'd appreciate it!
thanks
you cannot assign arrays in c, use memcpy
copy arrays:
memcpy(newvar, numbers[0], sizeof newvar);
Comments
Post a Comment