How to convert struct to char array in C

前端 未结 10 529
孤城傲影
孤城傲影 2020-12-19 03:00

I\'m trying to convert a struct to a char array to send over the network. However, I get some weird output from the char array when I do.

#include 

        
10条回答
  •  借酒劲吻你
    2020-12-19 03:18

    char is a signed type so what you are seeing is the two-compliment representation, casting to (unsigned char*) will fix that (Rowland just beat me).

    On a side note you may want to change

    for (i=0; i<4; i++) {
    //...
    }
    

    to

    for (i=0; i

提交回复
热议问题