I currently have an array of structs tht I need to iterate through.
NB. There is a separate thread asking about the use of String, I don't want to get into that in this thread as the two things are separate, at least in my head they are.
// Test data, will be dynamic when in use.
float BatVolts = 13.5;
float ACVolts = 236;
float PV1_Current = 5;
float PV2_Current = 6;
// New struct (xVar Type)
typedef struct{
String Name;
float * Ptr;
}xVar;
xVar ExposedVars[20]; // make an array of xVars
void MapFloatName(float * NewVarPtr, String NewName){
static int VarCount = 0;
ExposedVars[VarCount].Ptr = NewVarPtr;
ExposedVars[VarCount].Name = NewName;
VarCount++;
}
// Lots of other stuff and nonsense
Is this the right approach or should I be creating structs and indexing through their pointers without the array?
I believe this is possible but haven't ever tried and would know how to.
typedef struct{
float Value;
String Name;
float * Ptr;
}BatVolts;
typedef struct{
float Value;
String Name;
float * Ptr;
}ACVolts;
typedef struct{
float Value;
String Name;
float * Ptr;
}PV1_Current
typedef struct{
float Value;
String Name;
float * Ptr;
}PV2_Current
With structs defined as above can I get a pointer to the first and then increment it, to return a pointer to the second and so on?
If I can how would I know when I had reached the last one in memory?
Of course I may have simply missed the point somewhere ...
Feel free to be blunt.
Thanks
Al