Commit fd1ee590c638c019e3b0d466cf265bc67e549f41

Authored by bjeanlou
1 parent cf53766d

Update7 withHash

Showing 4 changed files with 45 additions and 10 deletions   Show diff stats
@@ -69,30 +69,30 @@ void print(tree t,FILE*stream,string prefix){ @@ -69,30 +69,30 @@ void print(tree t,FILE*stream,string prefix){
69 //common_end 69 //common_end
70 if(is_common_end(t)){ 70 if(is_common_end(t)){
71 if(is_straight_end(t)){ 71 if(is_straight_end(t)){
72 - printf("%s\n",word2); 72 + fprintf(stream,"%s\n",word2);
73 } 73 }
74 if(ends_with_apostrophe(t)){ 74 if(ends_with_apostrophe(t)){
75 - printf("%s's\n",word2); 75 + fprintf(stream,"%s's\n",word2);
76 } 76 }
77 } 77 }
78 //proper_end 78 //proper_end
79 if(is_proper_end(t)){ 79 if(is_proper_end(t)){
80 word2[0]=toupper(word2[0]); 80 word2[0]=toupper(word2[0]);
81 if(is_straight_end(t)){ 81 if(is_straight_end(t)){
82 - printf("%s\n",word2); 82 + fprintf(stream,"%s\n",word2);
83 } 83 }
84 if(ends_with_apostrophe(t)){ 84 if(ends_with_apostrophe(t)){
85 - printf("%s's\n",word2); 85 + fprintf(stream,"%s's\n",word2);
86 } 86 }
87 } 87 }
88 //acronyme_end 88 //acronyme_end
89 if(is_acronyme_end(t)){ 89 if(is_acronyme_end(t)){
90 strupper(word2); 90 strupper(word2);
91 if(is_straight_end(t)){ 91 if(is_straight_end(t)){
92 - printf("%s\n",word2); 92 + fprintf(stream,"%s\n",word2);
93 } 93 }
94 if(ends_with_apostrophe(t)){ 94 if(ends_with_apostrophe(t)){
95 - printf("%s's\n",word2); 95 + fprintf(stream,"%s's\n",word2);
96 } 96 }
97 } 97 }
98 free(word2); 98 free(word2);
@@ -107,3 +107,16 @@ void strupper(string str){ @@ -107,3 +107,16 @@ void strupper(string str){
107 for(int i=0;str[i]!='\0';i++) 107 for(int i=0;str[i]!='\0';i++)
108 str[i]=toupper(str[i]); 108 str[i]=toupper(str[i]);
109 } 109 }
  110 +
  111 +
  112 +bool is_in(dico d,string word){
  113 + byte endKind=end_kind(word);
  114 + if(!is_word(endKind)){
  115 + return false;
  116 + }
  117 + tree tmp=d[hash(word[0])];
  118 + for(int i=1;word[i]!='\0' && word[i]!='\'' && !is_empty(tmp);i++){
  119 + tmp=tmp->next[hash(word[i])];
  120 + }
  121 + return !is_empty(tmp) && (endKind & is_end(tmp));
  122 +}
@@ -19,5 +19,6 @@ void print(tree,FILE*,string); @@ -19,5 +19,6 @@ void print(tree,FILE*,string);
19 19
20 void strupper(string str); 20 void strupper(string str);
21 21
  22 +bool is_in(dico,string);
22 23
23 #endif 24 #endif
makefile 0 → 100644
@@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
  1 +#makefile pour la branche withHash
  2 +#nom de l'executeble
  3 +EXEC = dictionnaire
  4 +#nom du compilateur
  5 +CC = gcc
  6 +#warnings utilisés
  7 +WARN = -W -Wall -Wextra
  8 +#librairies
  9 +
  10 +#sources
  11 +SRC =$(wildcard *.c)
  12 +OBJ =$(subst .c,.o,$(SRC))
  13 +
  14 +#compilations
  15 +$(EXEC):*.o
  16 + $(CC) $^ -o $@
  17 +main.o:main.c
  18 + $(CC) $(WARN) -c $^
  19 +
  20 +%.o:%.c %.h
  21 + $(CC) $(WARN) -c $*.c
@@ -12,7 +12,7 @@ node* make_empty_node(){ @@ -12,7 +12,7 @@ node* make_empty_node(){
12 n->next[i]=make_empty_tree(); 12 n->next[i]=make_empty_tree();
13 return n; 13 return n;
14 } 14 }
15 -node* make_node(char l,int end){ 15 +node* make_node(char l,byte end){
16 node*n=malloc(sizeof(node)); 16 node*n=malloc(sizeof(node));
17 n->letter=l; 17 n->letter=l;
18 n->isEnd=end; 18 n->isEnd=end;
@@ -45,7 +45,7 @@ bool is_followed(const tree t){ @@ -45,7 +45,7 @@ bool is_followed(const tree t){
45 } 45 }
46 46
47 //functions is_end 47 //functions is_end
48 -bool is_end(const tree t){return isEnd;} 48 +bool is_end(const tree t){return t->isEnd;}
49 bool is_straight_end(const tree t){return t->isEnd & STRAIGHT_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;} 50 bool ends_with_apostrophe(const tree t){return t->isEnd & APOSTROPHE_END;}
51 51
@@ -74,7 +74,7 @@ byte end_kind(const string s){ @@ -74,7 +74,7 @@ byte end_kind(const string s){
74 if(isalpha(s[1])){ 74 if(isalpha(s[1])){
75 i++; 75 i++;
76 if(islower(s[1])) 76 if(islower(s[1]))
77 - while(islower[i]); 77 + while(islower(s[i]));
78 else{//if isupper(s[1]) 78 else{//if isupper(s[1])
79 while(isupper(s[i])); 79 while(isupper(s[i]));
80 endKind=16; 80 endKind=16;
@@ -85,7 +85,7 @@ byte end_kind(const string s){ @@ -85,7 +85,7 @@ byte end_kind(const string s){
85 return endKind; 85 return endKind;
86 } 86 }
87 bool is_word(const byte endKind){ 87 bool is_word(const byte endKind){
88 - return end_Kind!=0; 88 + return endKind!=0;
89 } 89 }
90 90
91 91