首页 > 解决方案 > 使用字符串数组引用结构成员?

问题描述

我有一些来自 Matlab/Simulink 的自动生成的 c 代码,其中包含参数值的结构,其中成员是它们自己的参数名称。像这样的东西

Param.ParameterName1 = 5;
Param.ParameterName2 = 10;

然后我有一个ParameterList包含参数名称的字符串 () 数组。我想做的是使用参数名称ParameterList来引用结构的成员,这样我就可以为参数分配新值。像这样的东西:

i = 1;
Param.ParameterList[i] = 10;

这甚至可能吗?还有其他方法可以解决这个问题吗?

谢谢。

标签: cstruct

解决方案


推荐阅读