title: Void pointers in a Linked List in C
body: <p>I have a program which has a function that returns a void * to a structure, but I think I'm overlooking something when casting the data.</p>
  
  <p>This function creates a structure which contains a string and int. The strings are read in from a file.</p>
  
  <pre><code>void * buildWord(FILE * fin)
  {
       void * ptr;
  
       char buf[100];
       Words * nw = (Words *)calloc(1, sizeof(Words));
  
       fgets(buf, 100, fin);
       strip(buf);
       nw-&gt;word = (char *)calloc(1, (strlen(buf) + 1));
       nw-&gt;length = strlen(buf);
  
       strcpy(nw-&gt;word, buf);
  
       ptr = &amp;nw;
  
       return ptr;
  }
  </code></pre>
  
  <p>Here is the function that calls this and accepts the void *.</p>
  
  <pre><code>Node * buildNode(FILE * in, void *(*buildData)(FILE * in) )
  {
       Node * nn = (Node *)calloc(1, sizeof(Node));
  
       nn-&gt;data = (Words*)((*buildData)(in));
       return nn;
  }
  </code></pre>
  
  <p>Here is the structure for Node</p>
  
  <pre><code>struct node
  {
       void * data;
       struct node * next;
  };
  typedef struct node Node;
  </code></pre>
  
  <p>I know the creation of the word structure is fine, but when I go to work with the nodes in the list, there is no data within it. I'm not sure why that is. Thanks!</p>