title: createBinaryTree is giving an infinite Loop and createBinarySearchTree is giving segmentation Fault
body: <p><code>createBinaryTree</code> is giving an infinite Loop and <code>createBinarySearchTree</code> is giving segmentation Fault.
  Could someone please guide me as I quite new to data structures.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  typedef struct node
  {
      int data;
      struct node *lchild;
      struct node *rchild;
  } * NODE;
  
  NODE createBinaryTree(NODE root)
  {
      NODE temp = (NODE)malloc(sizeof(struct node));
      printf("Enter the value of the node. \n Enter -1 for returning. \n");
      scanf(" %d", &amp;temp-&gt;data);
      if (temp-&gt;data == -1)
          return NULL;
      else
      {
          printf("For left Node of %d \n", temp-&gt;data);
          temp-&gt;lchild = createBinaryTree(temp-&gt;lchild);
          printf("For right Node of %d \n", temp-&gt;data);
          temp-&gt;rchild = createBinaryTree(temp-&gt;rchild);
      }
      return temp;
  }
  NODE createBinarySearchTree(NODE root, int ele)
  {
      NODE new_node;
      new_node = (NODE)malloc(sizeof(struct node));
      new_node-&gt;data = ele;
      new_node-&gt;lchild = new_node = NULL;
  
      if (root == NULL)
          return new_node;
  
      NODE parent = NULL;
      NODE curr = root;
  
      while (curr != NULL)
      {
          parent = curr;
          if (curr-&gt;data &lt; ele)
              curr = curr-&gt;rchild;
          else
              curr = curr-&gt;lchild;
      }
  
      if (ele &lt; parent-&gt;data)
          parent-&gt;lchild = new_node;
      else
          parent-&gt;rchild = new_node;
  
      return root;
  }
  
  void inorder(NODE ptr)
  {
      if (ptr != NULL)
      {
          inorder(ptr-&gt;lchild);
          printf("%5d", ptr-&gt;data);
          inorder(ptr-&gt;rchild);
      }
  }
  
  void postorder(NODE ptr)
  {
      if (ptr != NULL)
      {
          postorder(ptr-&gt;lchild);
          postorder(ptr-&gt;rchild);
          printf("%5d", ptr-&gt;data);
      }
  }
  
  void preorder(NODE ptr)
  {
      if (ptr != NULL)
      {
          printf("%5d", ptr-&gt;data);
          preorder(ptr-&gt;lchild);
          preorder(ptr-&gt;rchild);
      }
  }
  
  void main()
  {
      NODE root = NULL;
  
      printf("Enter 0.createBinaryTree \n");
      printf("Enter 1.createBinarySearchTree \n");
      printf("Enter 2.displayTree \n");
      printf("Enter 3.searchTree \n");
  
      int choice;
      printf("Enter your choice\n");
      scanf(" %d", &amp;choice);
  
      int tempvalue;
  
      while (1)
      {
          switch (choice)
          {
          case 0:
              root = createBinaryTree(root);
              break;
  
          case 1:
              printf("Enter Root Node\n");
              scanf(" %d", &amp;tempvalue);
              while (tempvalue != -1)
              {
                  root = createBinarySearchTree(root, tempvalue);
                  break;
                  printf("Enter Next Node.\n Enter -1 to exit\n");
                  scanf(" %d", &amp;tempvalue);
              }
              break;
  
          case 2:
              printf("\n Inorder Traversals \n");
              inorder(root);
              printf("\n Postorder Traversals \n");
              postorder(root);
              printf("\n Preorder Traversals \n");
              preorder(root);
              printf("\n ********* \n");
              break;
          case 4:
              exit(0);
          }
      }
  }
  </code></pre>