-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.cpp
More file actions
59 lines (52 loc) · 1.32 KB
/
input.cpp
File metadata and controls
59 lines (52 loc) · 1.32 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
#include "input.hpp"
void readDocument(std::string fileName, int* a) {
std::ifstream file;
file.open(fileName);
char characters[100];
while (!file.eof()) {
file.read(characters, 100);
for (int x = 0; x < file.gcount(); x++) {
a[(int)characters[x]] += 1;
}
}
file.close();
}
void compress(std::string input, std::string output, std::string code[256]) {
std::ifstream file;
std::ofstream out;
file.open(input);
out.open(output);
char characters[100];
while (!file.eof()) {
file.read(characters, 100);
for (int x = 0; x < file.gcount(); x++) {
outputCompress(out, characters[x], code);
}
}
file.close();
out.close();
}
void outputCompress(std::ofstream& output, char character,
std::string code[256]) {
static std::string result = "";
//std::cout << code[(int)character]<< " " ;
for (unsigned int x = 0; x< code[(int)character].length(); x++) {
result += code[(int)character][x];
if (result.length() == 8) {
printOut(output, result);
result = "";
}
}
}
void printOut(std::ofstream& output, std::string code) {
char character = 0;
for (unsigned int x = 0; x < code.length(); x++) {
character = character << 1;
int val = 1;
if (code[x] == 0) {
val = 0;
}
character += val;
}
output.put(character);
}