打印

数组结构体怎么引用

[复制链接]
650|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

使用特权

评论回复
5
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);

使用特权

评论回复
6
qhtflsw|  楼主 | 2016-4-20 18:54 | 只看该作者
static void DecGroup(Event_TypeDef *p)
{
        switch(p->e)
        {
………………
                }

}

使用特权

评论回复
7
aerwa| | 2016-4-22 08:14 | 只看该作者
应该可以传递吧,不过你的e是int,temp是char,会不会是这个引起。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

59

主题

164

帖子

4

粉丝