title: Printing words in a trie in C
body: <p>Populating the trie is no problem.  Words contain no numbers or spaces and only lower case letters.</p>
  
  <p>printTrieContents uses a buffer malloced in main.</p>
  
  <p>THE PROBLEM:
  if the trie contains the words "scores" and "something", "scores" will be printed but "something" will not.</p>
  
  <p>Everything else is okay.</p>
  
  <pre><code>struct trieNode {
    int count;
    struct trieNode *children[ALPHA_SIZE];
  };
  
  
  void printTrieContents(struct trieNode *root, char *buffer, int buffIndex){
          int i;
          for(i = 0; i &lt; ALPHA_SIZE; i++){
                  if(root-&gt;children[i] != NULL){
                          buffer[buffIndex] = i + 'a';
                          printTrieContents(root-&gt;children[i], buffer, buffIndex + 1);
                  }
                  if(!hasChildren(root)){
                          buffer[buffIndex] = '\0';
                          if(strlen(buffer) &gt; 0){
                                  printf("%s: %d\n", buffer, root-&gt;count);
                                  buffIndex = 0;
                          }
                  }   
          }
  }
  
  int hasChildren(struct trieNode *root){
          int i;
          for(i = 0; i &lt; ALPHA_SIZE; i++){
                  if(root-&gt;children[i] != NULL){
                          return 1;
                  }
          }
  return 0;
  }
  </code></pre>