[SOLVED] How do I add values to a struct array?

How do I add values to a struct array?

struct ch {
  long code;
  String holder;
}
ch[] = {
  {2528600, "Master"},
  {328780, "Guest"},
};

void setup() {
  ch[(sizeof(ch) / sizeof(ch[0]) + 1)] = {1234567, "User1"};
}

Deeonix:
How do I add values to a struct array?

Unfortunately, you cannot dynamically add to an array, you would need to define its max size and work with it that way.

Once defined, you need to use the dot operator to access elements of a struct inside a function.

void setup() {
  ch[0].code  = 1234567;
}

This works:

struct ch {
  long code;
  String holder;
};

const byte MaxEntries = 10;

ch Entries[MaxEntries] = {
  {2528600, "Master"},
  {328780, "Guest"}
};

byte CurrentEntries = 2;

void setup() {
  if (CurrentEntries < MaxEntries) {
    Entries[CurrentEntries].code = 1234567;
    Entries[CurrentEntries].holder = "User1";
    CurrentEntries++;
  }
}
void loop() {}