Is there a way to loop through structs and assign a value to their members during the process?
I'm not really sure if I composed the question correctly, so I'll try showing it in code, that is of course invalid, but hopefully serves as better example:
struct example {
int x;
/* ... */
};
struct example s1;
struct example s2;
int *structs[] = {
s1.x,
s2.x
};
int main(void) {
for (int i = 0; i < 2; i++) {
*structs[i] = i;
}
return 0;
}
Basically, I need to automate the process of assigning values to multiple structures, but I don't know how. Is this even possible in C?