-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
73 lines (59 loc) · 1.4 KB
/
Copy pathMain.cpp
File metadata and controls
73 lines (59 loc) · 1.4 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#define _CRT_SECURE_NO_WARNINGS
#include "Table.h"
#include "Tree.h"
#include "Node.h"
#include <stdlib.h>
#include <stdio.h>
#define SIZE 256
#define MSG 1000
int main()
{
Table *table = inizialise();
char file[] = "text.txt";
setTable(table, file);
Table * tableCount = clearTable(table);
int sizeTableCount = sizeTable(table);
Node *node = 0;
for (int i = 0; i < sizeTableCount; i++)
{
Tree *tree = (Tree *)malloc(sizeof(Tree));
tree->table = tableCount[i];
tree->code[0] = '\0';
tree->left = NULL;
tree->countRoot = tableCount[i].count;
tree->right = NULL;
add2List(&node, (tree));
}
for (int i = 0; i < sizeTableCount-1; i++)
{
Tree *t = (Tree *)malloc(sizeof(Tree));
int n1 = node->tree.countRoot;
int n2 = node->pnext->tree.countRoot;
t->countRoot = n1 + n2;
t->table.count = NULL;
t->table.letter = NULL;
t->code[0] = '\0';
Tree *tLeft = (Tree *)malloc(sizeof(Tree));
*tLeft = node->tree;
Tree *tRigth = (Tree *)malloc(sizeof(Tree));
*tRigth = (node->pnext)->tree;
t->left = tLeft;
t->right = tRigth;
add2List(&node, t);
deleteFirst(node);
deleteFirst(node);
}
makeCodes(&node->tree);
Tree *rootHoff = &node->tree;
FILE *stream = fopen(file, "r");
char msg[SIZE] = {'\0'};
printf("Code File \n");
for (int i = 0; i < SIZE; i++)
{
msg[i] = fgetc(stream);
char lett = msg[i];
inL(rootHoff, lett);
}
puts("\n");
fclose(stream);
}