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 | //-1 if word can't enter, 0if allready in dico, 1 if added |
16 | 16 | int i; |
17 | 17 | byte isIn, endKind=end_kind(word); |
18 | + printf("%x\n",endKind); | |
18 | 19 | if(!is_word(endKind)){ |
19 | - printf("incorrect word\n"); | |
20 | + printf("%s is incorrect\n",word); | |
20 | 21 | return -1; |
21 | 22 | } |
22 | 23 | tree*tmp=&d[hash(word[0])],*temp; |
23 | 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 | 26 | temp=tmp; |
26 | - tmp=&((*tmp)->next[hash(word[i])]); | |
27 | + tmp=&((*tmp)->next[hash(word[i+1])]); | |
27 | 28 | } |
28 | 29 | //if word is not ended at the end of the tree |
29 | 30 | if(is_empty(*tmp)){ |
... | ... | @@ -34,14 +35,14 @@ byte addto_dico(dico d,const string word){ |
34 | 35 | tmp=&((*tmp)->next[hash(word[i])]); |
35 | 36 | } |
36 | 37 | (*temp)->isEnd = endKind; |
37 | - printf("actions ended\n"); | |
38 | + printf("%s added\n",word); | |
38 | 39 | fflush(stdout); |
39 | 40 | } |
40 | 41 | //if word is ended |
41 | 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 | 46 | fflush(stdout); |
46 | 47 | } |
47 | 48 | return isIn; |
... | ... | @@ -88,7 +89,7 @@ void printto_file(dico d,FILE*stream){ |
88 | 89 | printf("sorry, we can't open the dictionary\n"); |
89 | 90 | return; |
90 | 91 | } |
91 | - printf("This is what the dictionnary contains :\n"); | |
92 | + printf("\n\nThis is what the dictionnary contains :\n"); | |
92 | 93 | for(int i=0;i<NBCHAR;i++){ |
93 | 94 | print(d[i],stream,""); |
94 | 95 | } |
... | ... | @@ -107,34 +108,29 @@ void print(tree t,FILE*stream,string prefix){ |
107 | 108 | string word2=calloc((strlen(prefix)+4),sizeof(char)); |
108 | 109 | strcpy(word2,word); |
109 | 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 | 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 | 134 | free(word2); |
139 | 135 | } |
140 | 136 | for(int i=0;i<NBCHAR;i++){ | ... | ... |
essai.txt
... | ... | @@ -0,0 +1 @@ |
1 | +baraban | ... | ... |
... | ... | @@ -14,11 +14,12 @@ int main(int argc, char* argv[]){ |
14 | 14 | return EXIT_FAILURE; |
15 | 15 | } |
16 | 16 | |
17 | - printf("hello world\n"); | |
17 | + printf("bienvenue dans le dictonnaire\n\n"); | |
18 | 18 | dico monDico; |
19 | 19 | make_empty_dico(monDico); |
20 | 20 | loadfrom_file(monDico,f); |
21 | 21 | printto_terminal(monDico); |
22 | 22 | delete_dico(monDico); |
23 | + fclose(f); | |
23 | 24 | return EXIT_SUCCESS; |
24 | 25 | } | ... | ... |
treeh.c
... | ... | @@ -7,7 +7,7 @@ tree make_empty_tree(){ |
7 | 7 | node* make_empty_node(){ |
8 | 8 | node*n=malloc(sizeof(node)); |
9 | 9 | n->letter='\0'; |
10 | - n->isEnd=0; | |
10 | + n->isEnd=NOT_AN_END; | |
11 | 11 | for(int i=0;i<NBCHAR;i++) |
12 | 12 | n->next[i]=make_empty_tree(); |
13 | 13 | return n; |
... | ... | @@ -46,12 +46,12 @@ bool is_followed(const tree t){ |
46 | 46 | |
47 | 47 | //functions is_end |
48 | 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 | 85 | } |
86 | 86 | } |
87 | 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 | 94 | return NOT_AN_END; |
93 | 95 | } |
94 | 96 | bool is_word(const byte endKind){ |
95 | 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 | 10 | #define NBCHAR 26 //A-Z |
11 | 11 | |
12 | 12 | #define NOT_AN_END 0x00 |
13 | + | |
13 | 14 | #define COMMON_END 0x03 |
14 | -#define PROPER_END 0x0B | |
15 | +#define PROPER_END 0x0C | |
15 | 16 | #define ACRONYME_END 0x30 |
17 | + | |
16 | 18 | #define STRAIGHT_END 0x15 |
17 | 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 | 48 | bool is_word(byte endKind);//pass end_kind() as parameter |
47 | 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 | 52 | #endif //TREEH_H | ... | ... |