Domanda

I have following structs defined in my header file,

struct nl_packet {
      int seq;
      FRAMETYPE type;
      CnetAddr dest;
      CnetAddr src;
      uint32_t checksum;
      size_t length;
      char data[NL_MAXDATA];
    };


struct seq_Info  {

   int seqNum;
   size_t length;
   char data[NL_MAXDATA];

};

struct msg_Received {

   CnetAddr src;
   struct seq_Info seqInfo[BUFSIZ];
   int lastReceived;

};

and then in another file, I have the following assignment that comes with the "incompatible types in assignment error",

msgRec[i].seqInfo[j].data = packet.data;

I do have other statements like this in the same method but they work perfectly fine,

msgRec[i].seqInfo[j].seqNum = packet.seq;
msgRec[i].seqInfo[j].length = packet.length;

Even though both, data fields in nl_packet struct and seq_Info struct have the same type, then is this error coming up ??

Thanks in advance

È stato utile?

Soluzione

You are assigning arrays. You can not do that. You have to copy the array contents. You may do it like this:

memcpy(msgRec[i].seqInfo[j].data, packet.data, sizeof(char)*NL_MAXDATA);

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top