JohnDoe
JohnDoe

Reputation: 915

adding values to arrays of defined size in for loop

I have defined 6 arrays, and each array can contain 10 values:

static s16 arr_A[10];
static s16 arr_B[10];
static s16 arr_C[10];
static s16 arr_D[10];
static s16 arr_E[10];
static s16 arr_F[10];

Now I have an existing function which gives me values of interest:

FunctionContainsValuesOfInterest(&adc_values[0]);

myValues = adc_values[GROUP_A];
myValues = adc_values[GROUP_B];
myValues = adc_values[GROUP_C];
myValues = adc_values[GROUP_D];
myValues = adc_values[GROUP_E];
myValues = adc_values[GROUP_F];

At each call of FunctionContainsValuesOfInterest() I get new values. Now I would like to create a loop where I fill for example the array arr_A[] wih 10 values of adc_values[GROUP_A], arr_B[] with 10 values of adc_values[GROUP_B].

What is here the best and most efective procedure?

Upvotes: 0

Views: 44

Answers (1)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 727077

Assuming that the type of adc_values element is the same as that of arr_Xs, i.e. s16, you can use memcpy function to copy whole or a portion of adc_values:

memcpy(arr_A, &adc_values[GROUP_A], sizeof(arr_A));

The assumption above is that adc_values[GROUP_A] is that ten consecutive items at adc_values[GROUP_A+i] for i between 0 and 9, inclusive, are the values that need to be copied into arr_A.

Upvotes: 1

Related Questions