dico.c
1.53 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
74
75
76
77
78
#include "dico.h"
void make_empty_dico(dico d){
for(int i=0;i<NBCHAR;i++)
d[i]=NULL;
}
void delete_dico(dico d){
for(int i=0;i<NB1CHAR;i++)
delete_tree(d[i]);
}
bool addto_dico(dico d,const string s){
byte endKind=end_kind(s);
if(!is_word(endKind)){
printf("incorrect word");
return true;
}
if(is_empty(d[hash(s[0])])){
d[hash(s[0])]=make_node(s[0],0);
addto_tree2(d[hash(s[0])],s+1,endKind);
return false;
}
else {
return addto_tree(d[hash(s[0])],s+1,endKind);
}
}
void loadfrom_keyboard(dico d){loadfrom_file(d,stdin);}
void loadfrom_file(dico d,FILE*stream){
if(stream==NULL){
printf("sorry, we can't open the file");
return;
}
char word[30]={0};
while(fscanf(stream,"%s",word)!=EOF)
addto_dico(d,word);
printf("load success");
}
void printto_terminal(dico d){printto_file(dico,stdout);}
void printto_file(dico d,FILE*stream){
if(stream==NULL){
printf("sorry, we can't open the file");
return;
}
if(d==NULL){
printf("sorry, we can't open the dictionary");
return;
}
for(int i=0;i<NBCHAR;i++){
print(d[i],stream,"");
}
}
void print(tree t,FILE*stream,string prefix){
//needs to check stream!=NULL
if(is_empty(t))
return;
if(is_end(t)){
if(is_acronyme_end(t)){
if(is_straight_end(t)){}
else{}
}
if(is_proper_end(t)){
if(is_straight_end(t)){}
else{}
}
if(is_common_end(t)){
if(is_straight_end(t)){}
else{}
}
}
for(int i=0;i<NBCHAR;i++){
print(t->next[i],stream);
}
}