title: Creating a linked list based on the number of elements requested by the user in C
body: <p>So I wanted to create a doubly linked circular list with the node structure: </p>
  
  <pre><code>typedef struct Node { //node structure
      int value;
      struct Node *next;
      struct Node *previous;
  } node;
  </code></pre>
  
  <p>At first, I had created my list as follows: </p>
  
  <pre><code>//allocate memory for the nodes
      node *first = malloc(sizeof(*first));
      node *second = malloc(sizeof(*second));
      node *third = malloc(sizeof(*third));
      node *fourth = malloc(sizeof(*fourth));
      node *fifth = malloc(sizeof(*fifth));
  
      { //define the nodes and link them together.(circular linked list)
          first-&gt;value = 1;
          first-&gt;next = second;
          first-&gt;previous = fifth;
  
          second-&gt;value = 2;
          second-&gt;next = third;
          second-&gt;previous = first;
  
          third-&gt;value = 3;
          third-&gt;next = fourth;
          third-&gt;previous = second;
  
          fourth-&gt;value = 4;
          fourth-&gt;next = fifth;
          fourth-&gt;previous = third;
  
          fifth-&gt;value = 5;
          fifth-&gt;next = first;
          fifth-&gt;previous = fourth;
      }
  </code></pre>
  
  <p>But then I realized that I do not know if the list should consist of 5 elements and wanted to ask the user about the size of the list. 
  The problem is that when I tried to implement a function called <code>createList()</code> and pass the list size as a parameter, I have no clue of how I should create a such list. I thought of creating a temporary pointer first with <code>-&gt;next</code> and <code>-&gt;previous</code> values as <code>NULL</code> but then how would I iterate through the input <code>n</code> and create new nodes if the <code>next</code> node is <code>NULL</code>? </p>
  
  <p>Thanks</p>