How to combine text and variable into the name of a pre-defined array?

I have been haggling with this now for two days. Looking online and trying various ideas I just can’t seem to get this to work or find comparable code to what I’m trying to accomplish. I think I have been pretty clear about what I am wanting to do.

I know the variable or array has to be predefined as dynamic variables are not possible.

I am trying to have the code formulate the array name from text “Remote_Device” and joining it with the Device_ID in order to populate the correct array item with incoming serial data.

I am currently getting the Error:

exit status 1
invalid operands of types ‘const char*’ and ‘const char [4]’ to binary ‘operator+’

See code for further explanation of goal.

int Remote_Device1[30];
int Remote_Device2[30];
int Remote_Device3[30];
int Remote_Device4[30];
int Remote_Device5[30];
int Remote_Device6[30];
int Remote_Device7[30];
int Remote_Device8[30];
int Remote_Device9[30];
int Remote_Device10[30];
int Remote_Device11[30];
int Remote_Device12[30];
int Remote_Device13[30];
int Remote_Device14[30];
int Remote_Device15[30];
int Remote_Device16[30];
int Remote_Device17[30];
int Remote_Device18[30];
int Remote_Device19[30];
int Remote_Device20[30];
int Remote_Device21[30];
int Remote_Device22[30];
int Remote_Device23[30];
int Remote_Device24[30];
int Remote_Device25[30];
int Remote_Device26[30];
int Remote_Device27[30];
int Remote_Device28[30];
int Remote_Device29[30];
int Remote_Device30[30];
int Remote_Device31[30];
int Remote_Device32[30];


String Device = getStringPartByNr(INData, ' ', 1);  //OUTSOURCED FUNCTION      

int Device_ID = Device.toInt();
int Dev;

for (Dev = 0; Dev < 32; Dev = Dev + 1) {
 if (Device_ID == Dev)
 {
  "Remote_Device" + Device_ID + "[0]" = Device_ID;   



/* Explanation of Goal:
 *
 * For:  Restrict to numbers less than 32 and process if this is so.
 * 
 * if (the Device ID received from the Serial Packet is = to the Dev value from the for loop  
 * 
 * Locate the appropriate predefined array that matches the Device_ID and populate [0] with the device 
 *   ID
 * 
 * in shorter terms,   
 * Device_ID = Dev_Value,  if true,  find predefined array  Remote_DeviceDevice_ID[0] and populate it with 
 * Device_ID
 * 
 *
 *--
 *Credit where credit is due:
 *
 *//OUTSOURCED FUNCTION 
 *https://github.com/BenTommyE/Arduino_getStringPartByNr 
 *
 */
  }

Thank You Ladies and Gents, in advance…

Hoffy

I don’t know if you realize you have created 32 arrays with 30 elements per array.

Anyway, unless I am not understanding this, you are overthinking this.

int Remote_Device1[30];
int Remote_Device2[30];
int Remote_Device3[30];

int Device_ID = 2;


void setup()
{
    Serial.begin(9600);
       
    if (Device_ID > 0 && Device_ID < 3)
    {
        // 1 to 3

        switch (Device_ID)
        {
            case 1:
                Remote_Device1[0] = Device_ID;
                Serial.println(Device_ID);
                Serial.println("Remote_Device1[0]");
                break;
            case 2:
                Remote_Device1[0] = Device_ID;
                Serial.println(Device_ID);
                Serial.println("Remote_Device2[0]");
                break;
            case 3:
                Remote_Device1[0] = Device_ID;
                Serial.println(Device_ID);
                Serial.println("Remote_Device2[0]");
                break;
               
        }
    }
}

void loop()
{

}
struct RemoteDevice {
  char* name;
  int id;
};

struct RemoteDevice device[] = {
  {"fridge", 3},
  {"car", 98"},
  {"lawnmower", 1}
};

#define DEVICES (sizeof(device) / sizeof(device[0]))

Now, if you want to find a device by id, the easy way to do it is just to iterate through the devices. The smarter way to do it is to initialise your array in order of device id, and to perform a binary chop search to find the device.

// note that this is sorted in order of ascending device id
struct RemoteDevice device[] = {
  {"lawnmower", 1},
  {"fridge", 3},
  {"car", 98"}
};


struct RemoteDevice *findDevice(int id) {
  int too_low = -1;
  int too_high = DEVICES;

  while(too_low +1 < too_high) {
    int check = (too_low + too_high) / 2;
    if(device[check].id == id) {
      return &device[check];
    }
    if(device[check].id < id) {
      too_low = check;
    }
    else {
      too_high = check;
    }
  }
  return NULL; // not found
}
"Remote_Device" + Device_ID + "[0]" = Device_ID;

That will never work. You can't deal with variable names in code. At runtime, there is no such thing as names for variables, they're all just memory addresses. The names are just there for you while you are writing, the compiler gets rid of them all when it compiles the code into a .hex file.

What you need to accomplish that is an array of arrays, that is a 2D array.

You want a 2-dimensional array:

int Remote_Device[32][30];  // Note: index is from 0 to 31, not 1 to 32.

  Remote_Device[Device_ID-1][0] = Device_ID;