Defining a struct array

Hi,
Trying to implement a struct array which i ideally create in a table, i have seen it done by using the sort of code used to define record[2], but the complier is looking for a "primary-expression before '{' token.

What do i need to put in for this code to work?

Thanks

Pete

typedef struct record_type
{
int one;
int two;
int three;
};

record_type record[8];

record[0].one = 1;
record[0].two = 2;
record[0].three = 3;
record[1].one = 4;
record[1].two = 5;
record[1].three = 6;
record[2] = record_type{1,2,3};

1 Like

Hi,

typedef struct
  {
      int one;
      int two;
      int three;
  }  record_type;

record_type record[8];

void setup()
{
}

void loop()
{
  record[0].one = 1;
  record[0].two = 2;
  record[0].three = 3;
  record[1].one = 4;
  record[1].two = 5;
  record[1].three = 6;
  record[2] = (record_type) {1,2,3};
}

Regars,
Mike

1 Like

Thank you ever so much!
I've been trying to work out what the complier meant for hours!
Now seeing your code i understand!
Again thanks for your help!

Pete

OR

record_type registers [5] = {
{ 1, 2, 3 },
{ 1, 2, 3 },
{ 1, 2, 3 },
{ 1, 2, 3 },
{ 1, 2, 3 }
};