Python struct.unpack equivalent in C -


what have in python

string lenght = 4

, can unpack values.

is there equivalent of function on python, in c?

in c, there no concept of "packing" this. whenever have char buffer such

char buf[128]; 

whether treat string or complex data structure you. simplest way define struct , copy data , forth array.

struct mystruct{   int data1;   int data2; };  char buf[sizeof(struct mystruct)]; struct mystruct mystruct; mystruct.data1 = 1; mystruct.data2 = 2; memcpy(buf, &mystruct, sizeof(struct mystruct)); 

please note there packing/padding may happen here. example, if have short in struct, compiler may use 4 bytes anyway. fails when have use pointers, such char* strings in structure.


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -