使用用户输入字符串打印Structure字段

时间:2017-04-04 18:00:27

标签: c

我正在尝试在C中试验一个用用户输入

打印Structure字段的东西

例如:

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 
}

我知道C不支持反射,但只是想知道可能还有其他方法。实际上,我的结构非常复杂,包括所有数据类型,数组,指针但是想要从上面的小结构开始。

感谢.....

0 个答案:

没有答案