title: How to insert multiple data in linked list
body: <p>This program asks for two data ( a name and an id), and then stores them in a linked list and then it should output all the data one by one. </p>
  
  <pre><code> #include &lt;stdio.h&gt;
   #include &lt;stdlib.h&gt;
   #include &lt;string.h&gt;
  
  
  struct Test
  {
    char name[16];
    int id;
  };
  
  typedef struct Node {
    struct Test structure;
    struct Node * next;
  
  }TNode;
  typedef TNodo* Node;
  
  void NewDatainNode(struct Test  p, Node *pp)
  {
    TNode *temp;
  
    temp = malloc(sizeof(struct Node));
  
    temp-&gt;structure = p;
    temp-&gt;next = NULL;
  
    *pp = temp;
  
  }
  
  void ReadData(struct Test * p)
  {
    printf("\nName:");
    scanf(" %s", p-&gt;name);
    printf("\nID:");
    scanf(" %d", &amp;p-&gt;id);
  }
  
  
  void ViewNodes(Node  node)
  {
   while(node != NULL)
  {
     printf("%s %d\n",node-&gt;structure.name, node-&gt;structure.id);
     node = node-&gt;next;
  }
  
  }
  
  int Menu()
  {
    int c;
  
    printf("\n\tM E N U ***\n"
       "1 - New\n"
       "2 - Print\n"
       "0 - Exit\n"
       "\n&gt;&gt; ");
     scanf(" %d", &amp;c);
  
    return c;
  }
  
  
  
  int main()
  {
    int c;
    struct Prova test;
  struct Node * list = NULL;
    do {
      c = Menu();
  
      switch (c)
      {
        case 1:  ReadData(&amp;test);
                 NewDatainNode(test, &amp;list);break;
        case 2:  ViewNodes(lista); break;
        default: c = 0;
      }
  
    } while (c != 0);
  
    return 0;
  }
  </code></pre>
  
  <p>The problem is that it outputs only the last data that has been inserted, what should i do to make it output all the data retrieved in function NuovaPrenotazione()?.</p>
  
  <p>UPDATE: Now the function <code>NewDatainNodes()</code> looks like this:</p>
  
  <pre><code>void NewDatainNode(struct Test  p, Node *pp)
  {
    TNode *temp;
  
    temp = malloc(sizeof(struct Node));
  
    temp-&gt;structure = p;
    temp-&gt;next = *pp;
  
    *pp = temp;
  
  }
  </code></pre>
  
  <p>Thanks to Sandeep for the correction, the function works even without a return value,the problem was <code>temp-&gt;structure = NULL</code>.</p>