title: c++ binary tree, need a way to return line number the word is on, not the word number
body: <p>here is my code at current. right now i am returning the word number as it occurs when i am reading the text file in, what i need to do is return the line number the word exists on and print this out next to each word that i return to the console.  so rather than "hello world" appearing as, hello - 1 world -2, i need - hello -1  world -1</p>
  
  <p>need help figuring out how to do this.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;sstream&gt;
  #include &lt;istream&gt;
  #include &lt;conio.h&gt;
  
      struct node
      {
          int key_value, lineNumber;
          char *word;
          struct node *left,*right;
      };
  
      struct node *inserttree(struct node *tree,char *s, int lineNumber)
      {
          int i;
  
        if (tree==NULL)
        {
          if ( ( tree = (struct node *) malloc( sizeof(struct node) ) ) !=NULL)
          {
            if ((tree-&gt;word=(char *) malloc(strlen(s)+1))==NULL)
            {
                free(tree);
                tree=NULL;
            }
            else
            {
                tree-&gt;left=NULL;
                tree-&gt;right=NULL;
                strcpy(tree-&gt;word,s);
                  tree-&gt;lineNumber = lineNumber ;
            }
          }
        }
  
        else if ((i=strcmp(tree-&gt;word,s))&gt;0)
        {
            tree-&gt;left=inserttree(tree-&gt;left,s, lineNumber);
        }
        else if (i&lt;0)
        {
            tree-&gt;right=inserttree(tree-&gt;right,s, lineNumber);
        }
  
        return tree;
      }
  
      void printtree(struct node *tree)
      {
  
          if (tree!=NULL)
          {
              printtree(tree-&gt;left);
              printf("%s %d\n",tree-&gt;word, tree-&gt;lineNumber);
  
              printtree(tree-&gt;right);
          }
      }
  
      //int search(struct node *tree)
      //{
      //  int key;
      //  tree-&gt;right-&gt;key_value = key;
      //  return key;
      //}
  
      void freetree(struct node *tree)
      {
          if (tree!=NULL)
          {
              free(tree-&gt;word);
              freetree(tree-&gt;left);
              freetree(tree-&gt;right);
              free(tree);
          }
      }
  
      int main(void)
      {
          FILE *f;
          char s[1024]; /*assumes a word cannot be longer than 1023 chars*/
          struct node *tree=NULL;
          int line = 1;
  
      if ((f=fopen("Test.txt","r"))==NULL)
          printf("Unable to open Test.txt\n");
          else
          {
              while (fscanf(f,"%1023s",s)!=EOF)
              tree=inserttree(tree,s, line++);
              fclose(f);
  
              printtree(tree);  //moved from inserttree
              freetree(tree);
          }
  
      system("pause");
      return 0;
      }
  </code></pre>