title: Using "->" to navigate structs with pointers
body: <p>I am trying to create a phone book, which is a binary search tree which has a linked list on the end of each leaf, but, I have encountered a "Segmentation fault (Core dumped)" error. I have a feeling it is caused by my "makenode" function which creates the first node of the tree. My structs are the following</p>
  
  <pre><code>typedef struct number{
      char number [20];
      struct number *next; 
  } Number;
  
  typedef struct list {
      Number *first, *last;
  } List;
  
  typedef struct tree {
      char name[20];
      struct tree * left;
      struct tree * right;
      List * next;
  } Tree;
  </code></pre>
  
  <p>And my makenode function is</p>
  
  <pre><code>Tree *makenode (char name[20], Tree *l, Tree *r, Number e) {
      Tree *newnode;
      newnode = malloc( sizeof(Tree));
      strncpy(newnode-&gt;name,name,19);
      newnode-&gt;next=malloc(sizeof(List));
      newnode-&gt;next-&gt;first=malloc(sizeof(Number));
      strncpy(newnode-&gt;next-&gt;first-&gt;number,e.number,11);
      newnode-&gt;left = l;
      newnode-&gt;right = r; 
  return newnode;
  }
  </code></pre>
  
  <p>I was just hoping for advice on whether the line</p>
  
  <pre><code>strncpy(newnode-&gt;next-&gt;number,e.number,11);
  </code></pre>
  
  <p>is the line causing the problem, and maybe some advice on why it is causing the problem.
  Thanks in advance.</p>