title: Using memcpy trying to copy one struct into a char[] buffer
body: <pre><code>#define ECHOMAX 100
  
  struct tDataPacket
  {
      int iPacket_number;
      char sData[ECHOMAX];
  };
  
  int main () {
      tDataPacket packet;
      packet.iPacket_number=10;
      strcpy(packet.sData,"Hello world");
      char buffer[sizeof(tDataPacket)];
  
      memcpy(buffer,&amp;packet.iPacket_number,sizeof(int));
      memcpy(buffer+sizeof(int),packet.sData,ECHOMAX);
  
      std::cout&lt;&lt;"Buffer = "&lt;&lt;buffer&lt;&lt;"END";
    return 0;
  }
  </code></pre>
  
  <p>In the above code I am trying to pack my structure in a char[] buffer so that I can send it to a UDP socket. But the output of the program is "" string. So nothing is getting copied to 'buffer'. Am I missing anything??</p>