title: How do I write huffman code into compressed file?
body: <p>So I have made a proper binary tree for searching characters that appear in the text file, but I'm struggling with making compressed file. I have a buffer:</p>
  <pre><code>struct BitBuffer {
  FILE* file; // Initialization skipped.
  unsigned char buffer = 0;
  unsigned count = 0;
  
  void outputBit(unsigned char bit) {
       buffer &lt;&lt;= 1;         // Make room for next bit.
       if (bit) {
           buffer |= 1; // Set if necessary.
           count++;              // Remember we have added a bit.
       }
       if (count == 8) {
           fwrite(&amp;buffer, sizeof(buffer), 1, file); //
           count = 0;
       }
  }
  </code></pre>
  <p>but I don't know how to create a code for a particular character. I mean I don't know how to find the proper path to the leaf that contains the searched letter and how do I keep the correct code. This is a university project and I can't use data containers such as vector, queue, map etc.</p>