From fd1ee590c638c019e3b0d466cf265bc67e549f41 Mon Sep 17 00:00:00 2001 From: Baptiste JL Date: Fri, 26 Apr 2019 23:16:40 +0200 Subject: [PATCH] Update7 withHash --- dico.c | 25 +++++++++++++++++++------ dico.h | 1 + makefile | 21 +++++++++++++++++++++ treeh.c | 8 ++++---- 4 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 makefile diff --git a/dico.c b/dico.c index fda9403..049e3ee 100644 --- a/dico.c +++ b/dico.c @@ -69,30 +69,30 @@ void print(tree t,FILE*stream,string prefix){ //common_end if(is_common_end(t)){ if(is_straight_end(t)){ - printf("%s\n",word2); + fprintf(stream,"%s\n",word2); } if(ends_with_apostrophe(t)){ - printf("%s's\n",word2); + fprintf(stream,"%s's\n",word2); } } //proper_end if(is_proper_end(t)){ word2[0]=toupper(word2[0]); if(is_straight_end(t)){ - printf("%s\n",word2); + fprintf(stream,"%s\n",word2); } if(ends_with_apostrophe(t)){ - printf("%s's\n",word2); + fprintf(stream,"%s's\n",word2); } } //acronyme_end if(is_acronyme_end(t)){ strupper(word2); if(is_straight_end(t)){ - printf("%s\n",word2); + fprintf(stream,"%s\n",word2); } if(ends_with_apostrophe(t)){ - printf("%s's\n",word2); + fprintf(stream,"%s's\n",word2); } } free(word2); @@ -107,3 +107,16 @@ void strupper(string str){ for(int i=0;str[i]!='\0';i++) str[i]=toupper(str[i]); } + + +bool is_in(dico d,string word){ + byte endKind=end_kind(word); + if(!is_word(endKind)){ + return false; + } + tree tmp=d[hash(word[0])]; + for(int i=1;word[i]!='\0' && word[i]!='\'' && !is_empty(tmp);i++){ + tmp=tmp->next[hash(word[i])]; + } + return !is_empty(tmp) && (endKind & is_end(tmp)); +} diff --git a/dico.h b/dico.h index ddf3ba6..4b5eafd 100644 --- a/dico.h +++ b/dico.h @@ -19,5 +19,6 @@ void print(tree,FILE*,string); void strupper(string str); +bool is_in(dico,string); #endif diff --git a/makefile b/makefile new file mode 100644 index 0000000..a85d202 --- /dev/null +++ b/makefile @@ -0,0 +1,21 @@ +#makefile pour la branche withHash +#nom de l'executeble +EXEC = dictionnaire +#nom du compilateur +CC = gcc +#warnings utilisés +WARN = -W -Wall -Wextra +#librairies + +#sources +SRC =$(wildcard *.c) +OBJ =$(subst .c,.o,$(SRC)) + +#compilations +$(EXEC):*.o + $(CC) $^ -o $@ +main.o:main.c + $(CC) $(WARN) -c $^ + +%.o:%.c %.h + $(CC) $(WARN) -c $*.c diff --git a/treeh.c b/treeh.c index 33bf024..ecd1f2a 100644 --- a/treeh.c +++ b/treeh.c @@ -12,7 +12,7 @@ node* make_empty_node(){ n->next[i]=make_empty_tree(); return n; } -node* make_node(char l,int end){ +node* make_node(char l,byte end){ node*n=malloc(sizeof(node)); n->letter=l; n->isEnd=end; @@ -45,7 +45,7 @@ bool is_followed(const tree t){ } //functions is_end -bool is_end(const tree t){return isEnd;} +bool is_end(const tree t){return t->isEnd;} bool is_straight_end(const tree t){return t->isEnd & STRAIGHT_END;} bool ends_with_apostrophe(const tree t){return t->isEnd & APOSTROPHE_END;} @@ -74,7 +74,7 @@ byte end_kind(const string s){ if(isalpha(s[1])){ i++; if(islower(s[1])) - while(islower[i]); + while(islower(s[i])); else{//if isupper(s[1]) while(isupper(s[i])); endKind=16; @@ -85,7 +85,7 @@ byte end_kind(const string s){ return endKind; } bool is_word(const byte endKind){ - return end_Kind!=0; + return endKind!=0; } -- libgit2 0.21.2