Reputation: 307
How do i select the second column of a 2-dimensional array. I have this array with about 30 values (LKT) and from there I have a 2-dimensional array (ScaledValues). The 2nd column of this 2-dimensional array will be filled with a scaled version of the original LKT array.
Initially, ActiveArray variable points to the LKT array. However, when I populate the 2nd column of the array in ScaledValues with scaled values of the first LKT array, how do I move ActiveArray to now point to the second column as the active array that i'll be using? i.e. After i fill the second column with the desired scale values, I'd like to work with those values and I want to use ActiveArray variable to denote that this new column is the active array.
I know there are other ways to do this i.e. I could create 2 separate individual arrays but I have to use the format that you see below. please assist. thanks.
Please let me know if i need to make my question clearer.
Thank you very much.
static const unsigned int LKT[30] = {
30, 29, 28, 27, 26, 25, 24, 23, 22,
21, 20, 19, 18, 17, 16, 15, 14, 13, 12,
11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
static unsigned int ScaledValues[30][2];
static volatile unsigned char ActiveArray = 0;
Upvotes: 0
Views: 115
Reputation: 13533
Reverse the ScaledValues array declaration:
unsigned int ScaledValues[2][30];
for (int i = 0; i < 30; i++) {
ScaledValues[0][i] = LKT[i];
ScaledValues[1][i] = scale(LKT[i]);
}
// Also need to make this a pointer
unsigned int * ActiveArray = ScaledValues[0]; // Original values
ActiveArray = ScaledValues[1]; // Scaled values
Upvotes: 1
Reputation: 43518
the easier way to manipulate this array could be done as following
first the definition should be in this way
static unsigned int ScaledValues[2][30];
then to copy LKT
to the first line
(and not column
)
memcpy(ScaledValues[0], LKT, 30*sizeof(unsigned int));
to access to the second line of the ScaledValues
array is
ScaledValues[1]
Upvotes: 0