Can you concatenate two reference a variable?

I have 5 variables named seat1, seat2, ... Seat 5.

Is it possible to pass an int through a function and get the corresponding variable's value?

i.e:

int seat3 [5];
seat3 [3] = 1;

void input (char num) {
    num = strcat("seat", num);
    num = strcat(num, "[3]");
    //somthing to turn "seat3[3]" into 1
    return num;
}

void loop () {
     input(3);
}

I'm new to Arduino, so thank you for your help!

Hi there,

I'm not too sure what you mean, do you mean you just want a function that will return the value of the array?
if so, you could do something like this instead:

int seat[5] = {20, 40, 60, 80, 100};

void tellMeArrayValue(int *arr, int index)
{
  Serial.print(F("The value in seat["));
  Serial.print(index);
  Serial.print(F("] is: "));
  Serial.println(arr[index]);

  delay(1000);
}

void setup(){
  Serial.begin(9600);
};

void loop () {
     tellMeArrayValue(seat, 0);
}

or were you wanting to change the value of one of the integers in the array? or, just wanting to get the value?

Sorry for the confusion. I need one value from the array.

Here's the code I'm trying to use it in. Maybe I'm just being lazy...

The [5] value in the array is the Arduino pin that corresponds to the seat.

char seat[15];

        for (i=1; i <= 5; i++) {
            /* make seat value into "seat" + i + "[5]"  */
            if (analogRead(seat))
            {
                 ...
            }

Ignore syntax.

Does that help?

Sorry, but it is no clearer to me

for (i=1; i <= 5; i++) {
/* make seat value into "seat" + i + "[5]" */
if (analogRead(seat[i]))
{
...
}

Ok, sorry...

I have a char array

int seat1 [5], seat2 [5], seat3 [5], seat4 [5], seat5 [5];

Within this for loop, I want to reference the 5th value of each seat array.

char seat[15];

        for (i=1; i <= 5; i++) {
            /* make seat value into "seat" + i + "[5]"  */
            if (analogRead(seat))
            {
                 ...
            }

So on the first loop, I want to pull the value of seat1 [5], on the second loop, seat2 [5], and so on...

I have 5 separate seat variables, so not just changing the array number.

Put each array in another array then seat[i][j]
Seat[5][5]

for (i=0; i <= 4; i++) {
/* make seat value into "seat" + i + "[5]" */
if (analogRead(seat[i][4])) //4 is the fifth element
{
...
}

I didn't realize you could stack arrays... cool.

Do I need to declare a big array, or does that just work?

ie:

int seat1 [5], seat2 [5], seat3 [5], seat4 [5], seat5 [5];

int allSeats [5] = seat1, seat2, seat3, seat4, seat5;

Try this example

int seats[][5] =
{
  {100, 101, 102, 103, 104},
  {105, 106, 107, 108, 109},
  {110, 111, 112, 113, 114},
  {115, 116, 117, 118, 119},
  {120, 121, 122, 123, 124}
};

void setup()
{
  Serial.begin(115200);
  for (int x = 0; x < 5; x++)
  {
    Serial.println(seats[x][4]);
  }
}

void loop()
{
}

I didn't know you you could do that. That's perfect! Thank you!

Well, Evan gave me the solution, but you gave me the specific details/syntax... Does it matter which I mark a "Solution"?

It does not matter to me