Question

I made a program wich use the Huffman Coding to compress and decompress .txt files (ANSI, Unicode, UTF-8, Big Endian Unicode...).

In the decompression I take characters from a binary tree and I put them into a .txt in binary mode:

Ofstream F;
F.open("example.txt", ios::binary);

I have to write into .txt file in binary mode because I need to decompress every type of .txt file (not only ANSI) so my simbols are the single bytes.

On Windows it puts every simbol but doesn't care about the Enter character!

For example, if I have this example.txt file:

Hello 
World!
=)

I compress it into example.dat file and I save the Huffman tree into another file (exampletree.dat). Now to decompress example.dat I take characters from the tree saved in exampletree.dat and I put them into a new .txt file through put() or fwrite(), but on Windows it will be like this:

HelloWorld!=)

On Ubuntu it works perfectly and saves also the Enter character!

It isn't a code error because if I print in the console the decompressed .txt file, it also prints the enter characters! So there is a problem in Windows! Could someone help me?

Was it helpful?

Solution

Did you try opening the file using a wordpad or any other advanced text editor(Notepad++) which identify LF as newline character. The default editor notepad would put it in a single line like you described.

This may not be the solution you are looking for. But the problem looks to be due to having LF as the line break instead of windows default CR/LF.

OTHER TIPS

It looks like it will be the difference in handling EndOfLine on Linux vs. Windows. The EOL can be just "\n" or "\r\n" - i.e. Windows usually puts 0x0d,0x0a at the end of lines. On Windows there's a difference between:

fopen( "filename", "w" );

fopen( "filename", "tw" );

quote: In text mode, carriage return–linefeed combinations are translated into single linefeeds on input, and linefeed characters are translated to carriage return–linefeed combinations on output

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top