-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhuffman.cpp
30 lines (25 loc) · 831 Bytes
/
huffman.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
#include <iostream>
#include <fstream>
#include <ctime>
#include <iomanip>
#include "compression.h"
int main(int argc, char **argv) {
if (argc != 4 || (std::string(argv[1]) != "-c" && std::string(argv[1]) != "-d")) {
std::cout << "Usage: huffman [-c|-d] %source% %destination%";
return 0;
}
std::string src = argv[2];
std::string dest = argv[3];
std::ifstream source;
std::ofstream destination;
source.open(src, std::ios::binary);
destination.open(dest, std::ios::binary);
std::clock_t time = clock();
if (std::string(argv[1]) == "-c") {
encode(source, destination);
} else {
decode(source, destination);
}
std::cerr << "Time spent:" << std::setprecision(3) << double(clock() - time) / CLOCKS_PER_SEC << " sec."
<< std::endl;
}