Go Down

Topic: Defining a struct array (Read 28542 times) previous topic - next topic

psfletcher

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};

mike_pa

Hi,

Code: [Select]

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

psfletcher

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

efficens

OR

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


Go Up