-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemp.txt
113 lines (104 loc) · 1.88 KB
/
temp.txt
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
if (cmp == NULL)
{
cmp = it->data;
count++;
tmp = it;
it = it->next;
str = remove(str, tmp);
}
else if (it->next == NULL)
{
if (cmp == it->data && it == str)
{
count++;
str = remove(str, it);
table = insertFirstf(table, count, cmp,NULL);
break;
}
else if(cmp == it->data)
{
count++;
tmp = it;
str = remove(str, tmp);
table = insertFirstf(table, count, cmp,NULL);
it = str;
cmp = it->data;
count = 0;
}
else
{
table = insertFirstf(table, count, cmp,NULL);
it = str;
cmp = it->data;
count = 0;
}
}
else if (cmp == it->data)
{
count++;
tmp = it;
it = it->next;
str = remove(str, tmp);
}
else
{
it = it->next;
}
}
free(str);
void decompress() {
FILE* output;
fopen_s(&output, "output.dat", "rb");
FILE* code;
fopen_s(&code, "codes.dat", "rb");
int extrabits;
char ch;
int i = 0;
int geh = getfile(output) - 2;
int no = geh;
int* arr = (int*)malloc(geh * sizeof(int));
fscanf_s(output, "%d \n", &extrabits);
while (geh != 0) {
ch = getc(output);
arr[i] = (int)ch;
i++;
geh--;
}
arr[i] = '\0';
codelist* h = NULL;
char letter = 0;
int codes[100];
i = 0;
while ((ch = getc(code)) != EOF) {
letter = ch;
while ((ch = getc(code)) != '\n') {
if (ch != ' ') {
codes[i] = ch - '0';
i++;
}
}
h = insertFirst(h, letter, codes, i);
i = 0;
}
char character[9];
char* Binary = (char*)malloc((8*no*sizeof(char)) + 1);
for (i = 0; i < no ; i++) {
chartobin(arr[i], character);
copy(Binary, character, 8*i );
}
codelist* it = h;
char test[100] = { '\0' };
int x = 1;
test[0] = Binary[0];
for (i = 1; i <(8*no) - extrabits; i++) {
for (it = h; it != NULL; it = it->next) {
if (strcmp(it->code, test) == 0 ) {
printf("%c", it->letter);
reset(test, x);
x = 0;
}
}
test[x] = Binary[i];
x++;
}
}