Show Posts
Pages: [1]
1  Forum 2005-2010 (read only) / Syntax & Programs / Use char array value to call int array value? on: January 23, 2011, 10:00:01 pm
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.
Pages: [1]