-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
47 lines (40 loc) · 1.35 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "../headers/huffman.h"
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;
int main(int argc, char **argv) {
string inputText;
if(argc > 1){
// capture text file from user
ifstream InputFile(argv[1]);
// check if file is valid
if(InputFile){
// read text file
std::stringstream buffer;
buffer << InputFile.rdbuf();
inputText = buffer.str();
InputFile.close();
// instance the Huffman structure
Huffman *huffmanAlgorithm = new Huffman(inputText);
string encodedText = huffmanAlgorithm->getEncodedString();
string decodedText = huffmanAlgorithm->getDecodedString();
// create and write output file that will contain the encoded text.
ofstream EncodedFile("encoded.txt");
EncodedFile << encodedText;
EncodedFile.close();
// create and write output file that will contain the decoded text.
ofstream DecodedFile("decoded.txt");
DecodedFile << decodedText;
DecodedFile.close();
// Compression ratio
cout << "Compression Ratio: " << huffmanAlgorithm->getCompressionRatio() << "%\n";
// Destrói a estrutura
huffmanAlgorithm->~Huffman();
return 0;
}
}
cout << "Error: input file not found.";
return 0;
}