I need help copying struct to char array

below memcpy do not copy anything from struct to char array. sendata stay as '\0'.

any thought?

1
2
3
4
5
6
7
8
9
    struct clientPacket cpacket;
    cpacket.transactionId = transaction;
    cpacket.op = DISTANCE;
    cpacket.p1X = p1->x;
    cpacket.p1Y = p1->y;
    cpacket.p2X = p2->x;
    cpacket.p2Y = p2->y;
    char *sendData = new char[CPACKETBUFSIZE];
    memcpy( sendData, &cpacket, sizeof( clientPacket ) );
Last edited on
turns out, I was doing the correct thing. verified with copying char array back to new struct.
Topic archived. No new replies allowed.