C generic array implementation
<p>I am trying to implement a generic array list in C. However, when the data type is any type other than int, the list wont contain the correct data. For example, like 123.1234 as a double, when the double is passed into the list, it will become 000.0000. One when the data type is int, it will have correct value. I don't know which part of the code is wrong, can anyone give me a hint? Thanks</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;
#include "genericADT.h"

struct list_type {
   void *data;
   int elementSize;
   int size;
   int capacity;
};

ListType create(int elementSize) {
   ListType listptr = malloc(sizeof(struct list_type));

   if (listptr != NULL) {
      listptr-&gt;size = 0;
      listptr-&gt;capacity = 10;
      listptr-&gt;elementSize = elementSize;
      listptr-&gt;data = malloc(10 * (listptr-&gt;elementSize));
      if (listptr-&gt;data == NULL) {
         free(listptr);
         listptr = NULL;
      }
   }
   return listptr;
}

void push(ListType listptr, void *item) {
   if (listptr-&gt;size &gt;= listptr-&gt;capacity) {
      void *temp = realloc(listptr-&gt;data, listptr-&gt;elementSize * (listptr-&gt;capacity + 100));
      if (temp != NULL) {
         listptr-&gt;capacity += 100;
         listptr-&gt;data = temp;

         memcpy(listptr-&gt;data + (listptr-&gt;size) * (listptr-&gt;elementSize), item, sizeof(listptr-&gt;elementSize));
         listptr-&gt;size++;
      }
   } else {
      memcpy(listptr-&gt;data + (listptr-&gt;size) * (listptr-&gt;elementSize), item, sizeof(listptr-&gt;elementSize));
      listptr-&gt;size++;
   }
}

void *get(ListType listptr, int index) {
   return listptr-&gt;data + index * (listptr-&gt;elementSize);
}

int size_is(ListType listptr) {
   return listptr-&gt;size;
}
</code></pre>