-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_database.c
68 lines (65 loc) · 1.47 KB
/
make_database.c
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "inc/btree.h"
void word_handle(char *word, int length)
{
int i, j;
for(i = 0; i < length; i ++) // remove phonetic //
{
if(word[i] == '/')
{
word[i] = '\0';
break;
}
}
for(j = 0; j < i; j ++) // remove '@' //
word[j] = word[j + 1];
// remove space at the end // abcde
word[j - 2] = '\0';
}
void create_btree_dictionary(BTA *root)
{
char line[200];
char word[20];
char translation[100000];
translation[0] = '\0';
FILE *fp;
if((fp = fopen("anhviet.txt", "r")) == NULL)
{
printf("Can not open anhviet.txt!\n");
return;
}
int i;
int first_word_flag = 1;
int word_count = 0;
fgets(line,200,fp);
do
{
if(line[0] == '@')
{
if(first_word_flag == 0)
{
btins(root, word, translation, strlen(translation));
translation[0] = '\0';
}
word_handle(line, strlen(line));
strcpy(word, line);
first_word_flag = 0;
word_count ++;
}
else
strcat(translation, line);
}while((fgets(line, 200, fp)) != NULL);
printf("Inserted %d words into btree dictionary!\n", word_count);
fclose(fp);
}
int main()
{
BTA *tree;
btinit();
tree = btcrt("database", 0, 0);
create_btree_dictionary(tree);
btcls(tree);
return 0;
}