0

主要结构

typedef struct {
   uint8 u8Status;
   uint8 u8NeighborTableEntries;
   uint8 u8StartIndex;
   uint8 u8NeighborTableListCount;
   /* Rest of the message is variable length */
   ZPS_tsAplZdpDiscNtEntry* pNetworkTableList;
                                              //pNetworkTableList is a pointer to 
                                              //the first   
                                              //entry in the list of reported
                                              //Neighbour table entries
 } ZPS_tsAplZdpMgmtLqiRsp;


typedef struct
{
   uint64 u64ExtPanId;
   uint64 u64ExtendedAddress;
   uint16 u16NwkAddr;
   uint8 u8LinkQuality;
   uint8 u8Depth;
   union
   {
     struct
     {
       unsigned u2DeviceType:2;
       unsigned u2RxOnWhenIdle:2;
       unsigned u2Relationship:3;
       unsigned u1Reserved1:1;
       unsigned u2PermitJoining:2;
       unsigned u6Reserved2:6;
    } ;
    uint8 au8Field[2];
 } uAncAttrs;
} ZPS_tsAplZdpDiscNtEntry;

我已经定义了 ZPS_tsAplZdpMgmtLqiRsp *pointer;

这个好像没问题。。

pointer->u8Status
pointer->u8NeighborTableEntries
pointer->u8StartIndex
pointer->u8NeighborTableListCount

但是我如何访问 ZPS_tsAplZdpDiscNtEntry 结构中的这些值

4

2 回答 2

0

您可以通过以下方式访问数组:pointer->pNetworkTableList 因此您可以从那里访问结构的所有元素..

例如访问索引为 0 的元素的 u64ExtPanId:

pointer->pNetworkTableList[0].u64ExtPanId = 1232;
于 2012-02-02T11:33:40.330 回答
0

你有指针,但你没有结构本身的实例。执行以下操作:

ZPS_tsAplZdpMgmtLqiRsp *pointer = (ZPS_tsAplZdpMgmtLqiRsp *)malloc(sizeof(ZPS_tsAplZdpMgmtLqiRsp));

...是的,您也应该为 pNetworkTableList 分配内存:

pointer->pNetworkTableList = (ZPS_tsAplZdpDiscNtEntry *)malloc(sizeof(ZPS_tsAplZdpDiscNtEntry));

那么你可以

 pointer->pNetworkTableList->u8Status = 12; 

等等。

不要忘记做

free(pointer->pNetworkTableList);
free(pointer);

在工作结束时。

于 2012-02-02T11:35:08.423 回答