-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTEXT
More file actions
50 lines (38 loc) · 1.02 KB
/
TEXT
File metadata and controls
50 lines (38 loc) · 1.02 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
#include <string.h>
size_t pack_word(struct Word *word, void *packed) {
unsigned char length = strlen(word->str);
unsigned char header = (word->part << 5) | length;
unsigned char *buffer = (unsigned char *)packed;
*buffer = header;
buffer++;
for (size_t i = 0; i < length; i++) {
buffer[i] = word->str[i];
}
return length + 1;
}
int i = 0;
while (words[i] != NULL) {
size_t bytes = pack_word(words[i], buffer);
buffer += bytes;
totalBytes += bytes;
i++;
}
size_t pack_dictionary(struct Word *words[], void *dict) {
size_t totalBytes = 0;
unsigned char *buffer = (unsigned char *)dict;
for (int i = 0; words[i] != NULL; i++) {
size_t bytes = pack_word(words[i], buffer);
buffer += bytes;
totalBytes += bytes;
}
*buffer = 0;
totalBytes++;
return totalBytes;
}
int i = 0;
while (words[i] != NULL) {
size_t bytes = pack_word(words[i], buffer);
buffer += bytes;
totalBytes += bytes;
i++;
}