我有很多内部变量,如a1-1,a1-2.a1-3,a2-1,......,我想在c语言中做成循环,来方便使用这些内部变量,不做循环,语句比较烦琐,修改起来工作量也较大,怎样实现?谢谢!
问题补充:
比如程序如下:
int c;
int f;
c=GetTagDouble("b0");
f=GetTagDouble("a0");
switch(c)
{
case 1:
{
switch(f)
{
case 1:
{
int static n11,n12,n13,n14;
char* s2;
char s3;
int n2;
s2=GetTagChar("a");
s3=*s2;
switch(s3)
{
case 'a':
{
n11=GetTagDouble("a1-1");
n11++;
SetTagDouble("a1-1",n11);
s3='\0';//
SetTagChar("a",&s3);
SetTagChar("b",s2);
break;
}
case 'b':
{
n12=GetTagDouble("a1-2");
n12++;
SetTagDouble("a1-2",n12);
s3='\0';
SetTagChar("a",&s3);
SetTagChar("b",s2);
break;
}
......
break;
}
case 2:
{
int static n21,n22,n23,n24;
char* s2;
char s3;
int n2;
s2=GetTagChar("a");
s3=*s2;
switch(s3)
{
case 'a':
{
n21=GetTagDouble("a2-1");
n21++;
SetTagDouble("a2-1",n21);
s3='\0';
SetTagChar("a",&s3);
SetTagChar("b",s2);
break;
}
case 'b':
{
n22=GetTagDouble("a2-2");
n22++;
SetTagDouble("a2-2",n22);
s3='\0';
SetTagChar("a",&s3);
SetTagChar("b",s2);
break;
}
......
break;
}
诸如此类的变量有好多,没有循环就是一直重复这样写程序?
十分感谢!
最佳答案
给你一段代码供你参考:
int i;
char tagn[20];
char num_a[10];
for(i=1;i<=24;i++)
{
sprintf(tagn,"NUM.A%d",i);
sprintf(num_a,"%d",i);
SetTagCharWait(tagn,num_a);
}
//代码的功能就是给NUM.A1-NUM.A24依次赋值
提问者对于答案的评价:
十分感谢!
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc274340.html