 <p>This line:</p> <pre><code>temp = (cell*)realloc(temp, sizeof(cell)); </code></pre> <p>invokes <strong>undefined behaviour</strong> since <code>temp</code> is not initialized. You should initialize it with, e.g., <code>cell *temp = NULL;</code> (understand that <code>realloc</code> can either take a <code>NULL</code> pointer in which case it is equivalent to <code>malloc</code>, or a previously <code>malloced/calloced/realloced</code> pointer).</p> <p>And <strong>don't cast the return from malloc</strong>. This is C, not C++. Search this site for why casting the <code>malloc</code> return value is frowned upon in C.</p>