Go Down

Topic: Use char array value to call int array value? (Read 4706 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
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy