File output with huffman coding

Hi I creating a code encodes and decodes a text file using Huffman coding. I was able to successfully code it but I am not able to decode it correctly since apparently the program keeps reading the same lines and doesn't create any end of line. Here is my code I could appreciate some help.

void decode(node* root, string codeStr, string &output)
{
node * n_root= root;
while (!codeStr.empty())
{
if (n_root->right == NULL && n_root->left == NULL)
{
output = output + n_root->letter;
n_root = root;
}
else
{
if (codeStr[0] == '1')
n_root = n_root->left;
else if (codeStr[0] == '0')
n_root = n_root->right;
else
output = output + codeStr[0];
codeStr.erase(0, 1);
}
}
output = output + "/n";
}

string code_line;
string output;
int length = 0;
for (int i = 0; i < 50; i++)
{
getline(encodedfile,code_line);
decode(root, code_line,output);
decodedfile.write(output.c_str(), output.size());
}

both texts are read correctly and root is the main root of the Huffman coding tree.

Topic archived. No new replies allowed.