title: Linked Lists in C without malloc
body: <pre><code>#include &lt;stdio.h&gt;
  
  typedef struct node
  {
        int i;
        struct node *next;
  }node;
  
  node getnode(int a)
  {
        struct node n;
        n.i=a;
        n.next=NULL;
        return n;
  }
  
  main()
  {
       int i;
       node newtemp,root,temp;
  
       scanf("%d",&amp;i);
       root=getnode(i);
       temp=root;
  
       while(i--)
       {
           newtemp=getnode(i);
  
           temp.next=&amp;newtemp;
           if(root.next==NULL)
           {
              root=temp;
           }
          temp=*(temp.next);
       }
  
  
       temp=root;
  
       while( temp.next != NULL )
       {
           printf(" %d ",temp.i);
           temp=*(temp.next);
       }
  }
  </code></pre>
  
  <p>I am trying to create a linked-list without using malloc. The programming is printing only the root and no nodes following it. I couldn`t find the bug. Had there been any memory issue, the gcc compiler would have thrown a segmentation fault.(?) Please ignore the poor programming style.. </p>