Typecasting struct to a char array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ashlekha
    New Member
    • Apr 2007
    • 1

    Typecasting struct to a char array

    Hi,

    I am doing socket programming

    I am receiving my payload message in a structure.
    now to encapsulate it i have to convert it into a buffer.
    Buffer is nothing but a charcter pointer array.

    Can anyone help me out with syntax of the above typecasting i.e from struct to buffer.

    I will be gratefull for your response.

    Thank You.
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Just cast the address of your struct to a char* and write sizeof(your_str uct) bytes
    through the socet:
    Code:
    char* buf= (char*)&your_struct);
    fwrite(buf, sizeof(your_struct), 1, socket_stream);
    kind regards,

    Jos

    Comment

    Working...