title: BST program in C
body: <p>Please help me with this. I keep getting seg faults!
  I want to use recursion to create and insert a new node.
  Please help me debug this.</p>
  
  <pre><code>//Create a Binary Search Tree From an array.
  struct Tree
  {
          int data;
      struct Tree *lchild;
      struct Tree *rchild;
  };
  struct Tree *root = NULL;
  struct Tree *node(int val)
  {
      struct Tree *tempnode;
      tempnode = (struct Tree*)malloc(sizeof(struct Tree));
      tempnode-&gt;data = val;
      tempnode-&gt;rchild = NULL;
      tempnode-&gt;lchild = NULL;
      return tempnode;
  }
  
  void createTree(struct Tree *curr, int val)
  {
      struct Tree *newnode = node(val);
  
      if (curr == NULL)
          curr = newnode;
      else if(val &lt; curr-&gt;data)
      {
          createTree(curr-&gt;lchild,val);
      }
      else if(val &gt; curr-&gt;data)
      {
          createTree(curr-&gt;rchild,val);
  
      }
      else
          printf("Error Similar data found\n");
  }
  
  void inorder(struct Tree *root)
  {
      if (root-&gt;lchild != NULL)
          inorder(root-&gt;lchild);
      printf("[%d]    ",root-&gt;data);
      if (root-&gt;rchild != NULL)
          inorder(root-&gt;rchild);
  }
  int main()
  {
  //    root = NULL;
      int i = 0, arr[5] = {41,12,32,23,17};
      for(i;i&lt;5;i++)
          createTree(root,arr[i]);
      inorder(root);
      return 0;
  }
  </code></pre>
  
  <p>why do I keep getting seg fault. Can someone explain me?
  Am I doing something I should not? Or am I missing at some point?</p>