guys.
I'm writing here because I cannot find an obvious error, so I'm stuck. Could you please help me?
Here's the code:
int arrayAAA[] = {6, 8, 10, 12};
int arrayBBB[] = {9, 15, 27, 41};
const int arrayAAALength = sizeof(arrayAAA)/sizeof(int);
const int arrayBBBLength = sizeof(arrayBBB)/sizeof(int);
int newArrayLength = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
String dir = "AAA";
if (dir == "AAA"){
//Copy existing array to the new one...
newArrayLength = arrayAAALength; //Get the size of source array
int newArray[newArrayLength]; //Make the new array of the same size
memcpy(newArray, arrayAAA, sizeof(arrayAAA)); //Copy content of the source array to the new one
/*
for (int i = 0; i < newArrayLength; i++){
Serial.print(newArray[i]); //Here everything works just fine...
Serial.print(" ");
}
*/
}
for (int i = 0; i < newArrayLength; i++){
Serial.print(newArray[i]); //But here I see this error: 'newArray' was not declared in this scope
Serial.print(" ");
}
Serial.println();
Serial.println();
}
What I'm trying to do is to copy the array to a new one, but depending on the circumstances I need to take different source arrays (AAA or BBB).
The problem is in checking the values of an newly crreated array:
'newArray' was not declared in this scope
if I try to check its valus outside of if statment.
It seems my stupid mistake, but I can't find it.