Go Down

Topic: Use char array value to call int array value? (Read 4536 times) previous topic - next topic

AssistantStuff

Hi all,
First post!  Hopefully a simple one.

How would I iterate over individual int arrays with the same name as a char array within a for loop?  I have a char array with a bunch of names.  I want to iterate through each name and for each name perform an operation with each of their int arrays values (each has a corresponding int array).

This isn't right, but this is what I would like to do:

Code: [Select]

#define asize(x)  (sizeof (x) / sizeof (x[0]))

char* nameSequence[] = {"bob","george","sam"};

int bob[3] = {1,0,0};
int george[3] = {3,1,6};
int sam[2] = {3,5};

for (int i = 0; i < asize(nameSequence); i++) {
 char* name = nameSequence[i];   //current name
 Serial.println(name);
                                 //now iterate through int array of that name
   for (int i = 0; i < asize(name); i++) {
     Serial.println(name[i]);    //print each value in int array of that name
   }
}



Serial output I would like:
bob
1
0
0
george
3
1
6
sam
3
5


Thank you for any assistance.

Go Up