Store array to other sketch file

Hello,

I declare theses arrays on the beginning sketch file:

uint8_t mac_addr_Server1[6] = {0x34, 0xb4, 0x72, 0x4d, 0x63, 0xc6 };
uint8_t mac_addr_Server2[6] = {0xb0, 0x7e, 0x11, 0xdd, 0xc7, 0x97 };
uint8_t mac_addr_Server_Used[6];

How can i set mac_addr_Server_Used=mac_addr_Server1 on the beginning?

Thank you.

Do this in setup()

  memcpy(mac_addr_Server_Used, mac_addr_Server1, sizeof(mac_addr_Server1));

Alternatively - If you use a Struct with an array inside then you can just use = for assignment

You could also have the known Mac addresses in a 2D array and only keep the index of the currently used one, that would save some memory

const uint8_t  macs[][6] = {
  {0x34, 0xb4, 0x72, 0x4d, 0x63, 0xc6 },
  {0xb0, 0x7e, 0x11, 0xdd, 0xc7, 0x97 }
};
uint8_t macIndex = 0;

How do you set macs[macIndex][6] to array [6] ?

I don’t get the question…

How do you select array at macIndex position ?
How do you print this array?

  for (int x = 0; x < 6; x++)
  {
    Serial.println(macs[macIndex][x], HEX);
  }
}

macs[macIndex] is a pointer to the start of the array.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.