数组结构体怎么引用

[复制链接]
983|6
 楼主| qhtflsw 发表于 2016-4-18 15:17 | 显示全部楼层 |阅读模式
定义
typedef struct
{
        unsigned char a;
        unsigned char b;
        unsigned char c;
        unsigned char d;       
        unsigned short int e;
        unsigned short int f;   
}
Event_TypeDef;

Event_TypeDef Event[4];

现在引用其中e。
如Event[0].e Event[1].e Event[2].e Event[3].e这四个元素需要批量处理

写了个子函数批量处理以上四个元素
void chuli(unsigned char temp)
{
  switch(temp)
{
case 0:temp = 1;break;
case 1:temp = 0;break;
default:break;
}

}


void main()
{
while(1)
{
chuli(Event[0].e);
chuli(Event[1].e);
chuli(Event[2].e);
chuli(Event[3].e);
}


}
这样写是传递不了值进去的。那么,要怎么写才能传递进去。关于结构体的形参传递不是很懂
luofeng2g 发表于 2016-4-18 15:20 | 显示全部楼层
这是当然的,传指针进去就好; 传值过程其实只是做了一份copy,原始数据时不会改变的!所以要么传指针,要么传引用(c++)
dirtwillfly 发表于 2016-4-18 19:59 | 显示全部楼层
c语言的话,一般就是用指针了
 楼主| qhtflsw 发表于 2016-4-19 10:44 | 显示全部楼层
dirtwillfly 发表于 2016-4-18 19:59
c语言的话,一般就是用指针了

知道用指针才行,能用这个例子简单的举例怎么使用指针吗?
如何使用指针引用去批量处理Event[0].e,Event[1].e,Event[2].e,Event[3].e
dirtwillfly 发表于 2016-4-19 20:10 | 显示全部楼层
qhtflsw 发表于 2016-4-19 10:44
知道用指针才行,能用这个例子简单的举例怎么使用指针吗?
如何使用指针引用去批量处理Event[0].e,Event ...

struct tag_arr
{
    int arr[1000][1000];
} test;

void fun(struct tag_arr *test);
 楼主| qhtflsw 发表于 2016-4-20 18:54 | 显示全部楼层
static void DecGroup(Event_TypeDef *p)
{
        switch(p->e)
        {
………………
                }

}
aerwa 发表于 2016-4-22 08:14 来自手机 | 显示全部楼层
应该可以传递吧,不过你的e是int,temp是char,会不会是这个引起。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

60

主题

168

帖子

4

粉丝
快速回复 在线客服 返回列表 返回顶部