I am looking for an automatic method to parsing a configuration file which store many stuct variable member values.
For example, we have a struct variable named as following:
struct
{
int a;
int b;
}struct_example
Then we have a configuration file stored this struct variable values:
struct_example:
a: 5
b: 10
And a simple way to set struct values would be like:
struct_example example;
// supporse we have read string of "5" and "10" from configuration file and store
// it to string variable string_a, string_b;
example.a = atoi(string_a);
example.b = atoi(string_b);
However, if we have 100 struct members, we have to write 100 lines code to set value; If we have 1000 struct members, we have to write even 1000 lines code for configuration.
Do we more automatic method for such struct member configuration? Such as a function:
void struct_member_config(string member_name, string member_value, struct_example* struct_variable);