title: Copying nodes in linked list C
body: <p>I am trying to duplicate a node in linked list. I am not sure if I am doing it correctly. I tried making test cases but did they were not successful. If some one could tell me if where I went wrong and what I did right, also what is the best way to test my code.</p>
  
  <pre><code>struct node 
  {
          int id;
          char side;
          int quantity;
          double price;
  };
  
  struct onode 
  {
          struct node* data;
          struct onode* next;
          struct onode* prev;
  };
  
  struct onode* newNode (struct node* data)
  
  {
      struct node* dataValue  = (struct node*) malloc(sizeof(struct node));
      struct onode* linkedlist = (struct onode*) malloc(sizeof(struct onode));
  
      linkedlist -&gt;data = (struct node*)malloc(sizeof(data)+1);
  
      if(dataValue &amp;&amp; data)
      {
          *dataValue = *data;
      }
  }
  </code></pre>
  
  <p>I have made changes in my code and added more description on what this function wants.
  one change : struct node is struct order.</p>
  
  <pre><code>struct order 
  {
          int id;
          char side;
          int quantity;
          double price;
  };
  
  struct onode 
  {
          struct order* data;
          struct onode* next;
          struct onode* prev;
  };
  
  
  /**
   * Returns a new linked list node filled in with the given order, The function
   * allocates a new order and copy the values stored in data then allocate a 
   * linked list node. If you are implementing this function make sure that you
   * duplicate, as the original data may be modified by the calling function.
   */
  
  struct onode* newNode (struct order* data)
  {
      struct order* dataValue  = (struct order*) malloc(sizeof(struct order));
      struct onode* linkedlist = (struct onode*) malloc(sizeof(struct onode));
  
      *dataValue = *data;
  
      linkedlist -&gt;data = dataValue;
  
      linkedlist-&gt;data-&gt;id = dataValue-&gt;id;
      linkedlist-&gt;data-&gt;price = dataValue-&gt;price;
      linkedlist-&gt;data-&gt;quantity = dataValue-&gt;quantity;
      linkedlist-&gt;data-&gt;side = dataValue-&gt;side;
      linkedlist-&gt;next-&gt;prev = NULL;
  
      return linkedlist;
  
  }
  </code></pre>