title: Storing object in BinarySearchTree leads to weird dereference problems
body: <p>For an assignment I need to write code that takes a string as input and counts what word is the most used in that string.</p>
  
  <p>We need to implement this using a Binary Search Tree of a structure called "WordCount" that contains a character array and the count of how many times the word appears. </p>
  
  <p>This is how the structure is defined.</p>
  
  <pre><code>struct wordcount {
      char word[80];
      int count;
  };
  
  typedef struct wordcount WordCount;
  </code></pre>
  
  <p>A binary search tree must have a way to create nodes, this is the code:</p>
  
  <pre><code>BSTnode* createNode(void* item) {
      BSTnode* newNode = (BSTnode*) malloc(sizeof(BSTnode));
  
      newNode-&gt;item = item;
      newNode-&gt;left = NULL;
      newNode-&gt;right = NULL;
  
      return newNode; 
  }
  </code></pre>
  
  <p>When I store the WordCount structure inside of the Binary Search Tree and attempt to access the item, and then access the word, I get a Segmentation Fault.</p>
  
  <p>If I just try to access the item of the tree, I get the char word array. This doesn't make sense because I'm storing the wordCount structure, so I should have to dereference it twice.</p>
  
  <pre><code>int main(int argc, char* argv[]) {
      if (argc &gt;= 1) {
          WordCount* firstWord = (WordCount*) malloc(sizeof(WordCount));
          strcpy(firstWord-&gt;word,argv[1]);
          firstWord-&gt;count = 0;
          BSTnode* BST = createNode(firstWord);
          printf("%s", BST-&gt;item); // should be BST-&gt;item-&gt;word...but this does not work and says that it cannot find "word" which is apart of 
      }
      /*int i;
      char string[80];
      for(i = 1; i &lt; argc; i++) {
          sscanf(argv[i], "%s", string);
          //printf("%s ", string);
          //insert(main, argv[i], wordCountCompare);
      }*/
  }
  </code></pre>
  
  <p>Any help is greatly appreciated. Let me know if my explanation was entirely vague or incomplete or if I'm overlooking something entirely.</p>
  
  <p>I also want to clarify that the printf statements are merely for debugging only they won't be apart of the actual program...however the point still stands.</p>
  
  <p>Definition of BSTnode:</p>
  
  <pre><code>struct bstnode {
      void *item;
      struct bstnode *left;
      struct bstnode *right;
  };
  typedef struct bstnode BSTnode;
  </code></pre>