I would like to fill an array by looping through an for loop.
Let's say I have:
int8 myArray[30] = {0}; // Declaring and initializing an array which contains maximum 30 elements
Adding elements to an array within a for loop:
for (i = 0; i<5; i++)
{
myArray[0+(i*5)] = getNumberfromFunction1();
myArray[1+(i*5)] = getNumberfromFunction2();
myArray[2+(i*5)] = getNumberfromFunction3();
myArray[3+(i*5)] = getNumberfromFunction4();
myArray[4+(i*5)] = getNumberfromFunction5();
myArray[5+(i*5)] = getNumberfromFunction6();
}
Each Element of the loop shall be filled like:
myArray[0] = getNumberfromFunction1();
myArray[1] = getNumberFromFunction2();
...
...
myArray[5] = getNumberFromFunction6();
myArray[6] = getNumberFromFunction1();
....
....
The first turn with i=0 I, the index is correct:
myArray[0] = ..
myArray[1] = ..
..
..
myArray[5] = ..
The problem starts when i = 1:
Than I will have instead of myArray[6], myArray[5].
The first index in the foor loop will be always overwritten by the last index of the foor loop.
Any suggestions how to handle this?