title: Translator with BST in C
body: <p>So I'm making a program that can take a word from keyboard and output the Spanish translation of it using a file with all the translations. Right now I'm using a BST as my function. In my code I use strtok() to break up the string that is being inputted from a file. However, every word has four random characters in front of them. Here is what I have...</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  #define SIZE 8001
  
  // BST code
  struct BSTnode{
      char engWord[128], spanWord[1000];
      struct BSTnode *left, *right;
  };
  
  struct BSTnode *root = NULL;
  
  struct BSTnode *newBSTNode(char *engWord, char *spanWord){
      struct BSTnode *newNode;
      newNode = (struct BSTnode*)malloc(sizeof(struct BSTnode));
      strcpy(newNode-&gt;engWord, engWord);
      strcpy(newNode-&gt;spanWord, spanWord);
      newNode-&gt;left = newNode-&gt;right = NULL;
      return newNode;
  }
  
  void insert(char *engWord, char *spanWord){
      struct BSTnode *parent, *current, *newnode = NULL;
      int res = 0;
      if(root == NULL){
          root = newBSTNode(engWord, spanWord);
          return;
      }
      for(current = root; current != NULL; 
      current = (res &gt; 0)?current-   &gt;right:current-&gt;left){
          res = strcasecmp(engWord, current-&gt;engWord);
          parent = current;
      }
      newnode = newBSTNode(engWord, spanWord);
      res &gt; 0?(parent-&gt;right = newnode):(parent-&gt;left = newnode);
      return;
  }
  
  void findEngWord(char *str){
      struct BSTnode *temp = NULL;
      int flag = 0, res = 0;
      if(root == NULL){
          printf("FAIL!!!!!!");
          return;
      }
      temp = root;
      int counter = 1;
      while(temp){
          if((res = strcasecmp(temp-&gt;engWord, str)) == 0){
              printf("\t%s\n\t%d BST nodes", temp-&gt;spanWord, counter);
              flag = 1;
              break;
          }
          temp = (res &gt; 0)?temp-&gt;left:temp-&gt;right;
          counter++;
      }
      if(!flag)
          printf("\t---NOT found (in BST)\n\t%d BST nodes", counter);
      return;
  
  }
  
  void openFileBST(){
      // open file
      FILE* filePnt = fopen("Spanish.txt", "r");
      char input[500], *first, *second;
  
      // If file is invalid
      if(filePnt == NULL){
          printf("Could not open file. Termination Program...");
          exit(0);
      }
  
      while(fgets(input, 500, filePnt) != NULL){
          first = strtok(filePnt, "\t");
          second = strtok(NULL, "\n");
          // Test prints
          printf("%s\n", &amp;first);
          printf("%s\n", &amp;second);
  
          insert(&amp;first, &amp;second);
      }
      fclose(filePnt);
  }
  
  void search(){
      char *tempStr, exitStr = "-1";
  
      // Ask user to input word
      printf("Enter a word you want to have translated. (type -1 to exit)
          \n-------------------------\n");
      while(1){
          printf("\n- ");
          fgets(tempStr, 99, stdin);
  
          // Failed exit statement
          //if(strcmp(tempStr, exitStr) == 0){
          //    printf("test");
          //    break;
          //}
  
  
          findEngWord(&amp;tempStr);
      }
  }
  
  int main()
  {
      openFileBST();
      search();
  }
  </code></pre>
  
  <p>Here is a picture of my output<a href="https://i.stack.imgur.com/fHsDP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fHsDP.png" alt="enter image description here"></a></p>
  
  <p>Because of the first four characters I'm pretty sure I can't correctly search for a English word. Is it something with my strtok function, or my code? Thank you guys for the help in advance!</p>