Pages: [1]   Go Down
Author Topic: initializing an array of floats within a structure during declaration.  (Read 1862 times)
0 Members and 1 Guest are viewing this topic.
Belgium
Offline Offline
Full Member
***
Karma: 6
Posts: 135
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi , I´m having trouble initializing an array of floats within a structure during declaration.

Code:
struct CalibParam {                    // Calibration Parameters aX^2 + bX + c
  float a;
  float b;
  float c;  
} ;
struct AnalogSensors {
   CalibParam CalPar[4] ;     // E2P array of structures ex: an.CalPar.b
   int  SurfTemp;
   // ... snip
   int  BarPres;
   long avgarray[4];
} an = { {0.0 , 5000.0/1024.0 , 0.0 } ,
         {0.0 , 5000.0/1024.0 , 0.0 } ,
         {0.0 , 1.0 , 0.0 },
         {0.0 , 1.0 , 0.0 } };
Gives : error: braces around scalar initializer for type 'int'
I´ve tried many things , I´m just missing the concept  smiley-confuse
« Last Edit: April 01, 2011, 09:39:08 am by astrofrostbyte » Logged

Gear: Arduino- Uno,Due,Ethernet,  OLS, Buspirate, J-Link, TDS1002, Rigol DG1022

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8687
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

More brackets!  You need a set for each struct or array:

    You need brackets for the structure AnalogSensors.
        Within that you need brackets for the array CalPar.
            Within that you need brackets for each of the four CalibParams.
    THEN you put a value for SurfTemp.

Code:
struct AnalogSensors {
   CalibParam CalPar[4] ;     // E2P array of structures ex: an.CalPar.b
   int  SurfTemp;
   // ... snip
   int  BarPres;
   long avgarray[4];
} an =
{ // AnalogSensors
  { //CalPar array
    {0.0 , 5000.0/1024.0 , 0.0 } ,  // CalibParam CalPar[0]
    {0.0 , 5000.0/1024.0 , 0.0 } ,  // CalibParam CalPar[1]
    {0.0 , 1.0 , 0.0 },                 // CalibParam CalPar[2]
    {0.0 , 1.0 , 0.0 }                  // CalibParam CalPar[3]
  },
  999 // SurfTemp
};
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Belgium
Offline Offline
Full Member
***
Karma: 6
Posts: 135
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you John for the clear explanation  smiley .
Logged

Gear: Arduino- Uno,Due,Ethernet,  OLS, Buspirate, J-Link, TDS1002, Rigol DG1022

Pages: [1]   Go Up
Jump to: