You can iterate through an array of structs but not the struct members.
Learn about Classes. You have a struct with function as well as data members.
You can add functions to structs too, but it's best to learn the whole shtick.
BTW, I'm not too sure about your struct... what happens when the String changes? Well maybe Strings have more "magic behind your back" about just where the data is kept.
Changes to the values in the struct will be handled by other code - my hope here is to grab a current set of 'state' type variables and dump them to an LCD screen.
Additionally, I'm looking for a way without using each of the 'names', such as 's_currentMode', more like a 'foreach' type structure that just blindly spits out each value blindly.
Maybe I'm using the wrong container for my purpose here and a struct is not appropriate. Ordinary variables might be the way to go - it just means more code. Please let me know if that's the case.
Anyway, the code you posted produced this error in my compiler :
no match for 'operator[]' in 'myStruct*'*
*Here's the complete code I used to test - is there something I've missed? * Thanks for your help. ```
*struct config_s
{
String s_currentMode;
boolean s_active;
boolean s_local;
}myStruct;
What I showed was an example of iterating through an array of 3 structs. To make that work you'd need to make an array of structs and use the array name rather than myStruct.
It's been too many years since I coded like that. I'd have to look it up to be sure of all the steps. And then I'd be doing something you might not, like having an array of myStructs....
Additionally, I'm looking for a way without using each of the 'names', such as 's_currentMode', more like a 'foreach' type structure that just blindly spits out each value blindly.
There isn't a way. You can't intelligently print the data in a struct without knowing how the struct is defined, which seems to be what you want to do.
You could use a class, instead of a struct, and put the code to print the class in the class. Then, all the code for dealing with the instance is encapsulated, and you can forget about it.
Melbfella:
I'm wanting to iterate through each item in the struct and print each value, something like this (which doesn't work) :
I agree with PaulS. You can't just iterate through a struct like that, any more than you can just automatically cook everything your wife has in the shopping bag. You need to apply some extra information to each item.
His data has a form that could allow the whole data to be streamed; String, bool, bool, String, bool, bool. Anyone care for a waltz? Well anyway it's not random.