Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to covert a structure to a byte array in C? [duplicate]

Tags:

arrays

c

struct

Possible Duplicates:
How to convert struct to char array in C
Portable way of writing a C struct to a file (Serialisation for C)

I am looking for converting a structure to byte array in C and i was confused in doing that.Please show me a right way in achieving that. Thanks in advance.

like image 535
venkatesh Avatar asked Dec 06 '25 04:12

venkatesh


1 Answers

A structure is a byte array. it starts at &mystruct and has the length of sizeof(mystruct_type) bytes.

If the binaries are to long or do contain gaps, check the #pragma pack settings.

hth

Maro

like image 101
Mario The Spoon Avatar answered Dec 07 '25 20:12

Mario The Spoon