Pages: [1]   Go Down
Author Topic: Use char array value to call int array value?  (Read 4181 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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.
Logged

Pages: [1]   Go Up
Jump to: