Value to variable name

I have some arrays which all have a similair var name. Underneat I have a “final” array which lists all the arrays which are active at that setup. In the part ‘Setup active ports’ it will go over all the elements in the “final” array. It should then get values (like the label or pin number) from the array with that name. So where ‘THIS IS WHERE THE MAGIC (SHOULD) HAPPEN’ is, it should print ‘22’ for the first, and ‘23’ for the second. However, it’s giving me the second character (‘sp_sw3’ = ‘p’) of the name of the array, instead of the second array value.

// Relay list
char    sp_sw3[][32]     =  {  "Light",       "22"  };
char    sp_sw4[][32]     =  {  "Fan",         "23"  };

// IR list
char    sp_ir8[][32]     =  {  "TV",          "00x1acb",  "04x74gx"  };
char    sp_ir9[][32]     =  {  "HDMI",        "02x2dds",  "20x1wsb"  };

// Active list
char    sp_active[][8]   =  {  "sp_sw4", "sp_sw3", "sp_ir8"  };

// General settings
int     serial_baud      =  9600;
int     pin_led          =  13;

/* ---------------------------------------------------------------- */

// Setup
void setup() {

  // Setup serial
  Serial.begin(serial_baud);
  Serial.print("SETUP: Serial communication initiated (");
  Serial.print(serial_baud);
  Serial.print(" baud).\n");

  // Setup LED pin
  pinMode(pin_led, OUTPUT);
  digitalWrite(pin_led, HIGH);
  Serial.print("SETUP: LED pin is declared on pin '");
  Serial.print(pin_led);
  Serial.print("'.\n");
  Serial.print("INFO: LED is ON during setup and goes OFF when completed.\n");

  // Setup active ports
  for (byte sp_idx = 0; sp_idx < sizeof(sp_active) / sizeof(sp_active[0]); sp_idx++) {
    String sp_check = sp_active[sp_idx];
    if (sp_check.startsWith("sp_sw")) {
      Serial.print("SETUP: List item '");
      Serial.print(sp_check);
      Serial.print("' is declared on pin '");
// THIS IS WHERE THE MAGIC (SHOULD) HAPPEN
      Serial.print(sp_check[1]);
// THIS IS WHERE THE MAGIC (SHOULD) HAPPEN
      Serial.print("'.\n");
    } else {
      Serial.print("SETUP: List item '");
      Serial.print(sp_check);
      Serial.print("' does not need to do anything during setup.\n");
    }
  }

  // Setup completed
  delay(1000);
  digitalWrite(pin_led, LOW);
  Serial.print("SETUP COMPLETED!\n");
  delay(1000);

}

/* ---------------------------------------------------------------- */

// Loop
void loop() {

  delay(1900);
  digitalWrite(pin_led, HIGH);
  delay(100);
  digitalWrite(pin_led, LOW);

}

  Serial.print(sp_check[1]); 1 is the index of the second element. Zero is the index of the first element

AWOL:   Serial.print(sp_check[1]); 1 is the index of the second element. Zero is the index of the first element

The outcome of that is:

...
SETUP: List item 'sp_sw4' is declared on pin 'p'.
SETUP: List item 'sp_sw3' is declared on pin 'p'.
SETUP: List item 'sp_ir8' does not need to do anything during setup.
...

And I would like to have:

...
SETUP: List item 'sp_sw4' is declared on pin '22'.
SETUP: List item 'sp_sw3' is declared on pin '23'.
SETUP: List item 'sp_ir8' does not need to do anything during setup.
...

Ok, I see now.
You need to use the & (address-of) operator, or use both indices.

AWOL:
Ok, I see now.
You need to use the & (address-of) operator, or use both indices.

Could you give me an example of this method?

char    sp_ir8[][32]     =  {  "TV",          "00x1acb",  "04x74gx"  };

Serial.print (sp_ir8[0][0]); should print 'T'. Serial.print (sp_ir8[0]); should print "TV" Serial.print (&sp_ir8[0][0]); should print "TV"..

AWOL: char    sp_ir8[][32]    =  {  "TV",          "00x1acb",  "04x74gx"  };

Serial.print (sp_ir8[0][0]); should print 'T'. Serial.print (sp_ir8[0]); should print "TV" Serial.print (&sp_ir8[0][0]); should print "TV"..

The problem is that "sp_ir8" is not known since this Serial output command is in a foreach run. "sp_sw3", "sp_sw4", "sp_ir8" and any other declared in the config (check var "sp_active") at the top need to go trough this foreach run.

I get the feeling that it pastes the outcome of "sp_check" as plain text. However; this plain text ("sp_sw3", "sp_sw4", "sp_ir8") should then be turned into the var name of the array to call for its information. (In case of "sp_ir8": label "TV" and IR code for 'turn on' "00x1abc").

HNJAMeindersma: I get the feeling that it pastes the outcome of "sp_check" as plain text. However; this plain text ("sp_sw3", "sp_sw4", "sp_ir8") should then be turned into the var name of the array to call for its information. (In case of "sp_ir8": label "TV" and IR code for 'turn on' "00x1abc").

It doesn’t work that way. Variable names only have significance at compile-time. At run-time all you have is memory addresses.

gfvalvo: It doesn’t work that way. Variable names only have significance at compile-time. At run-time all you have is memory addresses.

You're saying it will not work this way?

I guess that means that I will have to place an 'if /else if ' structure inside my foreach run to go over all possible arrays..

No. Maybe you need another array to point to the arrays you are using.

 char* sp_active[] = {sp_sw3, sp_ir8};