title: Copying structures into a dynamically allocated array of structures
body: <p>I'm trying to copy over a structure to an array of structures. </p>
  
  <p>I have a graph structure that has a field of a dynamically allocated array of vertices called </p>
  
  <pre><code>vlist 
  </code></pre>
  
  <p>and a integer storing the number of vertices in the vlist. </p>
  
  <p>Vertices have a name array as their inner field. 
  The function I am getting an error, takes a graph and a string and adds a vertex to that graph with that string as the name for the vertex. </p>
  
  <p>Here is the function: </p>
  
  <pre><code>int add_vertex(Graph *graph, const char name[]){
  
  if(name &amp;&amp; graph){
  
  /*Allocating space for new vertex*/
  vertex *new_vert = malloc(sizeof(vertex));
  
  /*Allocating space for vertex name*/
    new_vert-&gt;name = malloc(strlen(name)+1);
  
   /*Copying new vertex name to newly allocated vertex*/
    strcpy(new_vert -&gt; name, name);
  
   /*Adding a new space to vertex list*/
    graph -&gt; vlist = realloc(graph-&gt; vlist, sizeof(graph -&gt; vlist) + sizeof(vertex));
    graph -&gt; num_verts += 1;
    graph -&gt; vlist[graph-&gt;num_verts] = new_vert;
  
      return 1; 
  }
   else{
     return 0; 
   }
  </code></pre>
  
  <p>I am getting the error for the line: </p>
  
  <pre><code>  graph -&gt; vlist[graph-&gt;num_verts] = new_vert;
  </code></pre>
  
  <p>Error: </p>
  
  <pre><code>incompatible types when assigning to type 'vertex' from type 'struct vertex *'
  </code></pre>
  
  <p>I'm assuming this means that I'm copying values into the dynamic array incorrectly, but I can't figure out why. </p>
  
  <p>my Vertex is defined in a header file as : </p>
  
  <pre><code>typedef struct vertex{
    char *name;
  } vertex
  </code></pre>
  
  <p>Any help at all would be great, thank you!</p>
  
  <p>EDIT:</p>
  
  <p>Definition of graph</p>
  
  <pre><code>typedef struct Graph {
    vertex *vlist;
    int num_verts; 
  } Graph;
  </code></pre>