title: Code after function fails to execute - c++
body: <p>I am trying to write a program to simulate Huffman encoding and decoding. In order to do so, I needed to serialize a binary tree in a text file, so that I could read it again later and reconstruct the tree (when decoding the huffman file).</p>
  
  <p>However, after my function (readBinaryTree) that reads the file (which is recursive), the program just stops executing. I've never seen this before.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>if (!decode) {
      .
      .
      .
      //alot of stuff here
      .
      .
      .
   }
  
  
  else if (decode) {
      std::ifstream keyFile("hufftreekey.txt");
  
      Node* HuffTree = NULL;
  
       std::cout &lt;&lt; "PRE!" &lt;&lt; std::endl;
  
      readBinaryTree(HuffTree, keyFile);  //THIS FUNCTION EXECUTES, BUT NOTHING AFTER IT DOES
  
       std::cout &lt;&lt; "POST!" &lt;&lt; std::endl;
  
  
      std::map&lt;char, std::string&gt; codes = buildCodes(HuffTree);
  
      std::ofstream outFile;
      outFile.open ("mobydick_decoded.txt.huff");
  
      char c;
      std::ifstream input( argv[ 1 ] );
      while (input &gt;&gt; std::noskipws &gt;&gt; c) {
          if (codes.find(c) != codes.end()) { 
              std::string huffcode = codes[c];
              outFile &lt;&lt; huffcode;
          }
          else{
              std::cout &lt;&lt; "ERROR!" &lt;&lt; std::endl;
          }
  
      }
      outFile.close();
  
  }
  </code></pre>
  
  <p>Output in terminal is "PRE!", but it never prints "POST!". I don't get any error message, no exceptions are thrown, it just never prints, and nothing after the function is called is executed.</p>
  
  <p>This is the function:</p>
  
  <pre><code> void readBinaryTree(Node* root, std::ifstream &amp;fin){
   std::string s_val;
   char val;
   std::getline(fin, s_val);
   val = s_val[0];
   if(val == '#')
       return;
   else if(val == '_') {
      root = new Node();
      if (root == NULL) {
          std::cout &lt;&lt; "MEMORY ALLOC FAILURE!" &lt;&lt; std::endl;
       }
      root-&gt;content = '_';
      readBinaryTree(root-&gt;leftChild, fin);
      readBinaryTree(root-&gt;rightChild, fin);
  
   }
   else {
       root = new Node();
       if (root == NULL) {
          std::cout &lt;&lt; "MEMORY ALLOC FAILURE!" &lt;&lt; std::endl;
       }
       root-&gt;content = val;
       readBinaryTree(root-&gt;leftChild, fin);
       readBinaryTree(root-&gt;rightChild, fin);
   }
  </code></pre>
  
  <p>}</p>
  
  <p>This is not an infinite loop problem, the program finishes but it just seems to skip everything after the readBinaryTree function is called</p>