Sorry if i'm asking too many silly questions but i'm really stumped on this one. I understand if I set a variable inside a loop that that variable won't be within scope from the outside of the loop.
Usually I find that variables declared outside of a loop will be accessible inside the loop, modifiable within the loop, and hold their value when exiting the loop but in this case that doesn't seem to be happening.
There are books on the sd card. I'm saving the name of each book to an array from within a while loop. When the while loop is exited the array is still null.
How can I solve this? thanks
int amtBooks = 5; //this gets set previously but im not going to show all the code
// create an array the size of the amount of books
char* book[amtBooks] = { NULL };
// assign the name of each book to the array
int bookNum = 0;
while (true) {
File entry = root.openNextFile();
if (! entry) {
break; // no more files
}
book[bookNum] = entry.name();
Serial.println(book[bookNum]); // <--------PRINTS FINE HERE
bookNum ++;
}
root.close(); // close the stream
Serial.println(book[0]); <---ONCE OUT OF THE WHILE LOOP NOTHING DISPLAYS?
Serial.println(book[1]);
while (true) {
line .... the three lines of theif
block should be indented 2 spaces less .......... incorrect indentation adds confusion to debugging