简体   繁体   English

在C中访问结构成员

[英]Accessing structure members in C

Actually few hours back, I had posted a question but there was some error in my question (My bad!!). 实际上几小时前,我发布了一个问题,但是我的问题中有一些错误(我的糟糕!)。 I want to access the members of a structure (profile_t) which is placed inside a structure (profile_datagram_t) and profile_t is a array of structs.... 我想访问放置在结构(profile_datagram_t)内的结构(profile_t)的成员,而profile_t是结构数组。

            struct profile_t
          {
            unsigned char length;
            unsigned char type;
            unsigned char *data;
          };

            typedef struct profile_datagram_t
         {
            unsigned char src[4];
            unsigned char dst[4];
            unsigned char ver;
            unsigned char n;
            struct profile_t profiles[MAXPROFILES];     
         } header;

This sets the length of the first profile in the headers to 10: 这会将标题中第一个配置文件的长度设置为10:

header h;
h.profiles[0].length = 10;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM