Unpacking a C struct with Pythons struct module
<p>I am sending a struct in binary format from C to my python script.</p>

<p>My C struct:</p>

<pre><code>struct EXAMPLE {
    float val1;
    float val2;
    float val3;
}
</code></pre>

<p>How I send it:</p>

<pre><code>struct EXAMPLE *ex;
ex-&gt;val1 = 5.3f;
ex-&gt;val2 = 12.5f;
ex-&gt;val3 = 15.5f;

write(fd, &amp;ex, sizeof(struct EXAMPLE));
</code></pre>

<p>How I recieve:</p>

<pre><code>buf = sock.recv(12)
buf = struct.unpack('f f f', buf)
print buf
</code></pre>

<p>But when I print it out on the python side all I get is random garbage. I'm pretty sure there is something wrong with the struct definition in python but I'm not sure what.</p>