I am trying to experiment a thing in C to print the Structure field with the user input
Ex:
typedef struct
{
int A;
int B;
int C;
char str[50];
} my_struct;
void print ( struct my_struct *hndl , char* str )
{
/* Not sure how to implement this */
}
int main ( argc, argv[] )
{
my_struct hndl = { 1 , 2, 4, "hiall" };
print ( &hndl, "A" ) //should print the value of A which is 1;
print ( &hndlm "str" ) //should print the value of str which is hiall
}
I understand that C doesnt support reflection , but just wondering there might be some other way around. In real, I have my structures really complex with all data types, arrays, pointers but want to start with the above little structure.
Thanks.....