Commit 08822d7725e61a71cb00ab6ab6ca629a0c0eeacc
1 parent
8c671959
Update 9 withHash
Showing
7 changed files
with
58 additions
and
86 deletions
Show diff stats
@@ -15,15 +15,16 @@ byte addto_dico(dico d,const string word){ | @@ -15,15 +15,16 @@ byte addto_dico(dico d,const string word){ | ||
15 | //-1 if word can't enter, 0if allready in dico, 1 if added | 15 | //-1 if word can't enter, 0if allready in dico, 1 if added |
16 | int i; | 16 | int i; |
17 | byte isIn, endKind=end_kind(word); | 17 | byte isIn, endKind=end_kind(word); |
18 | + printf("%x\n",endKind); | ||
18 | if(!is_word(endKind)){ | 19 | if(!is_word(endKind)){ |
19 | - printf("incorrect word\n"); | 20 | + printf("%s is incorrect\n",word); |
20 | return -1; | 21 | return -1; |
21 | } | 22 | } |
22 | tree*tmp=&d[hash(word[0])],*temp; | 23 | tree*tmp=&d[hash(word[0])],*temp; |
23 | //1st, let's go through the tree, until the word is not in tree | 24 | //1st, let's go through the tree, until the word is not in tree |
24 | - for(i=1; word[i]!='; word[i]!='\0' && word[i]!='\'' && !is_empty(*tmp) ;i++){' && word[i]!='' && !is_empty(*tmp) ;i++){ | 25 | + for(i=0; word[i]!='; word[i]!='\0' && word[i]!='\'' && !is_empty(*tmp) ;i++){' && word[i]!='' && !is_empty(*tmp) ;i++){ |
25 | temp=tmp; | 26 | temp=tmp; |
26 | - tmp=&((*tmp)->next[hash(word[i])]); | 27 | + tmp=&((*tmp)->next[hash(word[i+1])]); |
27 | } | 28 | } |
28 | //if word is not ended at the end of the tree | 29 | //if word is not ended at the end of the tree |
29 | if(is_empty(*tmp)){ | 30 | if(is_empty(*tmp)){ |
@@ -34,14 +35,14 @@ byte addto_dico(dico d,const string word){ | @@ -34,14 +35,14 @@ byte addto_dico(dico d,const string word){ | ||
34 | tmp=&((*tmp)->next[hash(word[i])]); | 35 | tmp=&((*tmp)->next[hash(word[i])]); |
35 | } | 36 | } |
36 | (*temp)->isEnd = endKind; | 37 | (*temp)->isEnd = endKind; |
37 | - printf("actions ended\n"); | 38 | + printf("%s added\n",word); |
38 | fflush(stdout); | 39 | fflush(stdout); |
39 | } | 40 | } |
40 | //if word is ended | 41 | //if word is ended |
41 | else{ | 42 | else{ |
42 | - isIn=endKind & is_end(*tmp); | ||
43 | - (*tmp)->isEnd = endKind | is_end(*tmp); | ||
44 | - printf("action ended\n"); | 43 | + isIn=endKind & (*temp)->isEnd; |
44 | + (*temp)->isEnd = endKind | is_end(*temp); | ||
45 | + printf("%s allready in\n",word); | ||
45 | fflush(stdout); | 46 | fflush(stdout); |
46 | } | 47 | } |
47 | return isIn; | 48 | return isIn; |
@@ -88,7 +89,7 @@ void printto_file(dico d,FILE*stream){ | @@ -88,7 +89,7 @@ void printto_file(dico d,FILE*stream){ | ||
88 | printf("sorry, we can't open the dictionary\n"); | 89 | printf("sorry, we can't open the dictionary\n"); |
89 | return; | 90 | return; |
90 | } | 91 | } |
91 | - printf("This is what the dictionnary contains :\n"); | 92 | + printf("\n\nThis is what the dictionnary contains :\n"); |
92 | for(int i=0;i<NBCHAR;i++){ | 93 | for(int i=0;i<NBCHAR;i++){ |
93 | print(d[i],stream,""); | 94 | print(d[i],stream,""); |
94 | } | 95 | } |
@@ -107,34 +108,29 @@ void print(tree t,FILE*stream,string prefix){ | @@ -107,34 +108,29 @@ void print(tree t,FILE*stream,string prefix){ | ||
107 | string word2=calloc((strlen(prefix)+4),sizeof(char)); | 108 | string word2=calloc((strlen(prefix)+4),sizeof(char)); |
108 | strcpy(word2,word); | 109 | strcpy(word2,word); |
109 | //common_end | 110 | //common_end |
110 | - if(is_common_end(t)){ | ||
111 | - if(is_straight_end(t)){ | ||
112 | - fprintf(stream,"%s\n",word2); | ||
113 | - } | ||
114 | - if(ends_with_apostrophe(t)){ | ||
115 | - fprintf(stream,"%s's\n",word2); | ||
116 | - } | 111 | + if(is_common_end(t) && is_straight_end(t)){ |
112 | + fprintf(stream,"%s\n",word2); | ||
117 | } | 113 | } |
118 | - //proper_end | ||
119 | - if(is_proper_end(t)){ | ||
120 | - word2[0]=toupper(word2[0]); | ||
121 | - if(is_straight_end(t)){ | ||
122 | - fprintf(stream,"%s\n",word2); | ||
123 | - } | ||
124 | - if(ends_with_apostrophe(t)){ | ||
125 | - fprintf(stream,"%s's\n",word2); | ||
126 | - } | 114 | + if(is_common_end(t) && ends_with_apostrophe(t)){ |
115 | + fprintf(stream,"%s's\n",word2); | ||
116 | + } | ||
117 | + //proper_end1 | ||
118 | + word2[0]=toupper(word2[0]); | ||
119 | + if(is_proper_end(t) && is_straight_end(t)){ | ||
120 | + fprintf(stream,"%s\n",word2); | ||
121 | + } | ||
122 | + if(is_proper_end(t) && ends_with_apostrophe(t)){ | ||
123 | + fprintf(stream,"%s's\n",word2); | ||
127 | } | 124 | } |
128 | //acronyme_end | 125 | //acronyme_end |
129 | - if(is_acronyme_end(t)){ | ||
130 | - strupper(word2); | ||
131 | - if(is_straight_end(t)){ | ||
132 | - fprintf(stream,"%s\n",word2); | ||
133 | - } | ||
134 | - if(ends_with_apostrophe(t)){ | ||
135 | - fprintf(stream,"%s's\n",word2); | ||
136 | - } | 126 | + strupper(word2); |
127 | + if(is_acronyme_end(t) && is_straight_end(t)){ | ||
128 | + fprintf(stream,"%s\n",word2); | ||
129 | + } | ||
130 | + if(is_acronyme_end(t) && ends_with_apostrophe(t)){ | ||
131 | + fprintf(stream,"%s's\n",word2); | ||
137 | } | 132 | } |
133 | + | ||
138 | free(word2); | 134 | free(word2); |
139 | } | 135 | } |
140 | for(int i=0;i<NBCHAR;i++){ | 136 | for(int i=0;i<NBCHAR;i++){ |
essai.txt
@@ -0,0 +1 @@ | @@ -0,0 +1 @@ | ||
1 | +baraban |
@@ -14,11 +14,12 @@ int main(int argc, char* argv[]){ | @@ -14,11 +14,12 @@ int main(int argc, char* argv[]){ | ||
14 | return EXIT_FAILURE; | 14 | return EXIT_FAILURE; |
15 | } | 15 | } |
16 | 16 | ||
17 | - printf("hello world\n"); | 17 | + printf("bienvenue dans le dictonnaire\n\n"); |
18 | dico monDico; | 18 | dico monDico; |
19 | make_empty_dico(monDico); | 19 | make_empty_dico(monDico); |
20 | loadfrom_file(monDico,f); | 20 | loadfrom_file(monDico,f); |
21 | printto_terminal(monDico); | 21 | printto_terminal(monDico); |
22 | delete_dico(monDico); | 22 | delete_dico(monDico); |
23 | + fclose(f); | ||
23 | return EXIT_SUCCESS; | 24 | return EXIT_SUCCESS; |
24 | } | 25 | } |
treeh.c
@@ -7,7 +7,7 @@ tree make_empty_tree(){ | @@ -7,7 +7,7 @@ tree make_empty_tree(){ | ||
7 | node* make_empty_node(){ | 7 | node* make_empty_node(){ |
8 | node*n=malloc(sizeof(node)); | 8 | node*n=malloc(sizeof(node)); |
9 | n->letter='\0'; | 9 | n->letter='\0'; |
10 | - n->isEnd=0; | 10 | + n->isEnd=NOT_AN_END; |
11 | for(int i=0;i<NBCHAR;i++) | 11 | for(int i=0;i<NBCHAR;i++) |
12 | n->next[i]=make_empty_tree(); | 12 | n->next[i]=make_empty_tree(); |
13 | return n; | 13 | return n; |
@@ -46,12 +46,12 @@ bool is_followed(const tree t){ | @@ -46,12 +46,12 @@ bool is_followed(const tree t){ | ||
46 | 46 | ||
47 | //functions is_end | 47 | //functions is_end |
48 | bool is_end(const tree t){return t->isEnd;} | 48 | bool is_end(const tree t){return t->isEnd;} |
49 | -bool is_straight_end(const tree t){return t->isEnd & STRAIGHT_END;} | ||
50 | -bool ends_with_apostrophe(const tree t){return t->isEnd & APOSTROPHE_END;} | 49 | +bool is_straight_end(const tree t){return (t->isEnd & STRAIGHT_END);} |
50 | +bool ends_with_apostrophe(const tree t){return (t->isEnd & APOSTROPHE_END);} | ||
51 | 51 | ||
52 | -bool is_common_end(const tree t){return t->isEnd & COMMON_END ;} | ||
53 | -bool is_proper_end(const tree t){return t->isEnd & PROPER_END;} | ||
54 | -bool is_acronyme_end(const tree t){return t->isEnd & ACRONYME_END;} | 52 | +bool is_common_end(const tree t){return (t->isEnd & COMMON_END);} |
53 | +bool is_proper_end(const tree t){return (t->isEnd & PROPER_END);} | ||
54 | +bool is_acronyme_end(const tree t){return (t->isEnd & ACRONYME_END);} | ||
55 | 55 | ||
56 | 56 | ||
57 | 57 | ||
@@ -85,44 +85,14 @@ byte end_kind(const string s){ | @@ -85,44 +85,14 @@ byte end_kind(const string s){ | ||
85 | } | 85 | } |
86 | } | 86 | } |
87 | //then let's consider the end | 87 | //then let's consider the end |
88 | - if(s[i]=='\0') | ||
89 | - return endKind & STRAIGHT_END; | ||
90 | - if(s[i]=='\''&&s[i+1]=='s'&&s[i+2]=='\0') | ||
91 | - return endKind & APOSTROPHE_END; | 88 | + if(s[i]=='\0'){ |
89 | + return (endKind & STRAIGHT_END); | ||
90 | + } | ||
91 | + if(s[i]=='\'' && s[i+1]=='s' && s[i+2]=='\0'){ | ||
92 | + return (endKind & APOSTROPHE_END); | ||
93 | + } | ||
92 | return NOT_AN_END; | 94 | return NOT_AN_END; |
93 | } | 95 | } |
94 | bool is_word(const byte endKind){ | 96 | bool is_word(const byte endKind){ |
95 | return endKind!=0; | 97 | return endKind!=0; |
96 | } | 98 | } |
97 | - | ||
98 | - | ||
99 | - | ||
100 | - | ||
101 | - | ||
102 | -bool addto_treeIT(tree*t,const string word ,byte endKind){ | ||
103 | - bool isIn; | ||
104 | - int i; | ||
105 | - //1st, let's go through the tree, until the word is not in tree | ||
106 | - for(i=1; word[i]!='\0' && word[i]!='\'' && !is_empty(*t) ;i++){ | ||
107 | - t=&((*t)->next[hash(word[i])]); | ||
108 | - } | ||
109 | - printf("hi\n"); | ||
110 | - //if word is not ended at the end of the tree | ||
111 | - if(is_empty(*t)){ | ||
112 | - isIn=false; | ||
113 | - for(; word[i]!='\0' && word[i]!='\'';i++){ | ||
114 | - *t=make_node(tolower(word[i]),NOT_AN_END); | ||
115 | - t=&((*t)->next[hash(word[i])]); | ||
116 | - } | ||
117 | - (*t)->isEnd=endKind; | ||
118 | - printf("actions ended\n"); | ||
119 | - } | ||
120 | - //if word is ended | ||
121 | - else{ | ||
122 | - isIn=endKind & is_end(*t); | ||
123 | - (*t)->isEnd=endKind | is_end(*t); | ||
124 | - printf("action ended\n"); | ||
125 | - } | ||
126 | - return isIn; | ||
127 | -} | ||
128 | - |
treeh.h
@@ -10,9 +10,11 @@ | @@ -10,9 +10,11 @@ | ||
10 | #define NBCHAR 26 //A-Z | 10 | #define NBCHAR 26 //A-Z |
11 | 11 | ||
12 | #define NOT_AN_END 0x00 | 12 | #define NOT_AN_END 0x00 |
13 | + | ||
13 | #define COMMON_END 0x03 | 14 | #define COMMON_END 0x03 |
14 | -#define PROPER_END 0x0B | 15 | +#define PROPER_END 0x0C |
15 | #define ACRONYME_END 0x30 | 16 | #define ACRONYME_END 0x30 |
17 | + | ||
16 | #define STRAIGHT_END 0x15 | 18 | #define STRAIGHT_END 0x15 |
17 | #define APOSTROPHE_END 0x2A | 19 | #define APOSTROPHE_END 0x2A |
18 | 20 | ||
@@ -46,10 +48,5 @@ bool ischar_of_word(char);//tells if char can be in a word | @@ -46,10 +48,5 @@ bool ischar_of_word(char);//tells if char can be in a word | ||
46 | bool is_word(byte endKind);//pass end_kind() as parameter | 48 | bool is_word(byte endKind);//pass end_kind() as parameter |
47 | byte end_kind(string); | 49 | byte end_kind(string); |
48 | 50 | ||
49 | -//recursive can only be called in a addto_dico | ||
50 | -//bool addto_tree(tree,const string,byte); | ||
51 | -//void addto_tree2(tree,const string,byte); | ||
52 | -//bool addto_treeIT(tree*,const string,byte); | ||
53 | - | ||
54 | 51 | ||
55 | #endif //TREEH_H | 52 | #endif //TREEH_H |