C dynamic vector of struct
<p>I have the following struct for a dynamic vector:</p>

<pre><code>typedef struct {
    TElement *data;
    int len;
}Vector;
</code></pre>

<p>And 2 functions, one to initialize the vector and the other one to append an element:</p>

<pre><code>Vector *initVector()
{
    Vector *v;
    v = malloc(sizeof(TElement));
    v-&gt;len = 0;
    return v;
}
void append(Vector *v, TElement element)
{
    v = (Vector *)realloc(v, (v-&gt;len + 1) * sizeof(TElement));
    v-&gt;data[v-&gt;len++] = element;
}
</code></pre>

<p>When i try to append an element, the program crashes and I don't know why, any ideas?</p>