I have a struct like this:
static struct F_t {
char *_1;
char *_2;
char *_3;
char *_4;
char *_5;
char *_6;
char *_7;
char *_8;
char *_9;
char *_10;
char *_11;
char *_12;
} F = { 0 };
According to some values from stdin, it's set properly.
The "problem" is that I retrieve it from string, and I need set it properly. I'm using this function currently:
static inline void
setf(int i, char *value)
{
/* Nothing to do. */
if(i > 12)
return;
if(i == 1)
F._1 = value;
else if(i == 2)
F._2 = value;
else if(i == 3)
F._3 = value;
else if(i == 4)
F._4 = value;
else if(i == 5)
F._5 = value;
else if(i == 6)
F._6 = value;
else if(i == 7)
F._7 = value;
else if(i == 8)
F._8 = value;
else if(i == 9)
F._9 = value;
else if(i == 10)
F._10 = value;
else if(i == 11)
F._11 = value;
else if(i == 12)
F._12 = value;
}
I've tried by using macros.. but as it's set in run-time, it will not possible. I know that if have no reflections, modern things like this, etc. But maybe there is something that I do not know. Probably it's possible in C++. But no. I want pure C.
Any suggestion is very appareciated. Thanks in advance.