title: Getting bit sequence from a trie for huffman coding
body: <p>i currently have a trie built from the frequence of how many times a char appears in a in File. Now im trying to go from the root to each child and build a bit sequence for every letter (each leaf is a letter). Im using a preorder whilest doing this and everytime it goes to the left child of a node it´s suppose to add a "1" to the bit sequence and right a "0". However i cant find a good way to do this, i have tried using strings with strncat() and then when i found a leaf i have trouble removing the last char from the string so i have used strncpy(thestring, thestring, strlen(thestring) - 1) etc etc. Is there any way to walk trough the whole tree and add the bit?</p>
  
  <pre><code>Table *fill_table(node *root, Table *hufftable, bit_buffer *b)
  {
  if(root-&gt;left == NULL &amp;&amp; root-&gt;right == NULL){
      hufftable[(int)root-&gt;data].bseqe = bit_buffer_to_string(b);
      bit_buffer_remove_bit(b);
      return hufftable;
  }
  else{
      bit_buffer_insert_bit(b, 1);
      fill_table(root-&gt;left, hufftable, b);
      bit_buffer_insert_bit(b, 0);
      fill_table(root-&gt;right, hufftable, b);
  }
  
  return hufftable;
  </code></pre>
  
  <p>}</p>
  
  <p>This is an example of what i have trie, the issue with this is that 1. it gets seg fault and 2. the bitbuffer is given to us(this is a school assignment) and we are not allowed to change it. the bit_buffer_remove_bit takes away the first bit in the sequence not the last </p>