title: How to read in .txt file line by line to binary search tree
body: <p>Im trying to make a binary search tree and read in a text file line by line as a node for each line e.g.:</p>
  
  <pre><code>Dave Smith 0728492940
  Ed James 0956294587
  </code></pre>
  
  <p>So that then I can get the user to enter a name "Dave" and it will bring up their full name and phone number. I just am not sure how to implement reading the text file in to a binary search tree line by line to create a node for each line. At the moment I am just printing out the text file without putting it into the BST.
  Code so far is below:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  struct node {
      int data;
      struct node* left;
      struct node* right;
  } ;
  
  //tree wrapper structure
  struct tree {
      struct node *root;
  } ;
  
  typedef struct tree Tree;
  typedef struct node Node;
  
  //create a new tree
  Tree *new_tree() {
      Tree *t = malloc(sizeof(Tree));
      t-&gt;root = NULL;
      return t;
  }
  
  //create a new node
  Node* NewNode(int data) {
    Node* node = malloc(sizeof *node);
    node-&gt;data = data;
    node-&gt;left = NULL;
    node-&gt;right = NULL;
  
    return(node);
  }
  //insert in to the binary tree
  Node* insert(Node* node, char *data) {
    // 1. If the tree is empty, return a new, single node
    if (node == NULL) {
      return(NewNode(*data));
    }
    else {
      // 2. Otherwise, recur down the tree
      if (*data &lt;= node-&gt;data) node-&gt;left = insert(node-&gt;left, data);
      else node-&gt;right = insert(node-&gt;right, data);
  
      return(node); // return the (unchanged) node pointer
    }
  }
  //search for nodes to see if they exist
  bool NodeSearch(Node* node,int data) {
      if(node==NULL) return false;
      else if(node-&gt;data == data) return true;
      else if(data  &lt;= node -&gt;data) return NodeSearch(node-&gt;left, data);
      else return NodeSearch(node-&gt;right, data);
  }
  
  int main(){
  
      FILE *f;
      char s[1000];
  
      f=fopen("phone.txt", "r");
      if(!f)
          return 1;
      while (fgets(s,1000,f)!=NULL) {
          printf("%s\n", s);
      }
      fclose(f);
      return 0;
  }
  </code></pre>