title: trying to create a linked list using a function that takes a struct and sets the value
body: <pre><code>#include &lt;iostream&gt;
  using namespace std;
  </code></pre>
  
  <p>the structure </p>
  
  <pre><code>struct intnode { int value;
  struct intnode *next; };
  typedef struct intnode IntNode;
  </code></pre>
  
  <p>the code used to create a new node and set the new value</p>
  
  <pre><code>IntNode *intnode_construct(int value, IntNode *next) {
  IntNode *p = (IntNode*)malloc(sizeof(IntNode));
  
  assert (p != NULL);
  p-&gt;value=value;
  p-&gt;next = next;
  return p;
  }
  
  
  
      int main(int argc, const char * argv[]){
  
  
          IntNode *head1=NULL;
          IntNode *head2=NULL;
          IntNode *cur= NULL;
  
      head1 = intnode_construct(1, cur);
  </code></pre>
  
  <p>the values should be 1,3,5,7</p>
  
  <pre><code>for(int i=1;i&lt;10;(i=i+2))
          {
  
          cur = intnode_construct(i, cur);
  
  
          }
          cur=head1;
  </code></pre>
  
  <p>printing the function</p>
  
  <p>as soon as I run the program it gives me a runtime error</p>
  
  <pre><code>        do{
          cout&lt;&lt;cur-&gt;value&lt;&lt;endl;
              cur=cur-&gt;next;
          }
          while(cur-&gt;next != NULL);
      return 0;
      }
  </code></pre>