S
sean.scanlon
can someone help understand how i can could access a struct field
dymanically like: foo->fields ?
when i try to compile this i get the following error: 'struct pwd' has
no member named 'fields'
is there a way to treat fields as the member name of the struct?
example code:
struct pwd {
char *first;
char *last;
char *bar;
};
struct pwd *foo;
char* fields[] = {"first", "last", "bar"};
int main (int argc, char* argv[ ]) {
int i;
const int f_size = ( sizeof fields ) / ( sizeof fields[0] );
for (i = 0; i<f_size;i++) {
printf("%d == %s (%s)\n", i, fields, foo->fields);
}
return 0;
}
Thanks for any help,
-sean
dymanically like: foo->fields ?
when i try to compile this i get the following error: 'struct pwd' has
no member named 'fields'
is there a way to treat fields as the member name of the struct?
example code:
struct pwd {
char *first;
char *last;
char *bar;
};
struct pwd *foo;
char* fields[] = {"first", "last", "bar"};
int main (int argc, char* argv[ ]) {
int i;
const int f_size = ( sizeof fields ) / ( sizeof fields[0] );
for (i = 0; i<f_size;i++) {
printf("%d == %s (%s)\n", i, fields, foo->fields);
}
return 0;
}
Thanks for any help,
-sean