Writing and reading structs from binary file that contain other structs (C)
<p>I have to write/read from a binary file some structs that I created, but when reading them back in, I get some nasty errors.</p>

<p>Take for example this construction:</p>

<pre><code>typedef struct items
{
    char name[21], power[21];
    int stock;
    double price;
} ITEMS;

typedef struct shop
{
    char name[21];
    int numOfItems;
    ITEMS *arr;
} SHOP;
</code></pre>

<p>And now, I can create an array of SHOP and fill everything as is (creating  an dynamic array for ITEM, for each SHOP[i]), but I'm not sure if:</p>

<p>fwrite(); actually writes the whole array, with all the info that is filled in for the ITEM's
and when i use fread() it gives some access violation error.</p>

<p>What would be the correct approach, aside from using .txt files for I/O.</p>

<p>Here is a code sample:<a href="http://pastebin.com/79TtvQ9t" rel="nofollow">http://pastebin.com/79TtvQ9t</a></p>