Commit cf53766d11f27ec7a900769e0177568e952b1144

Authored by bjeanlou
1 parent 003d3e48

update2 dico

Showing 3 changed files with 47 additions and 12 deletions   Show diff stats
@@ -5,7 +5,7 @@ void make_empty_dico(dico d){ @@ -5,7 +5,7 @@ void make_empty_dico(dico d){
5 d[i]=NULL; 5 d[i]=NULL;
6 } 6 }
7 void delete_dico(dico d){ 7 void delete_dico(dico d){
8 - for(int i=0;i<NB1CHAR;i++) 8 + for(int i=0;i<NBCHAR;i++)
9 delete_tree(d[i]); 9 delete_tree(d[i]);
10 } 10 }
11 11
@@ -39,7 +39,7 @@ void loadfrom_file(dico d,FILE*stream){ @@ -39,7 +39,7 @@ void loadfrom_file(dico d,FILE*stream){
39 printf("load success"); 39 printf("load success");
40 } 40 }
41 41
42 -void printto_terminal(dico d){printto_file(dico,stdout);} 42 +void printto_terminal(dico d){printto_file(d,stdout);}
43 void printto_file(dico d,FILE*stream){ 43 void printto_file(dico d,FILE*stream){
44 if(stream==NULL){ 44 if(stream==NULL){
45 printf("sorry, we can't open the file"); 45 printf("sorry, we can't open the file");
@@ -58,21 +58,52 @@ void print(tree t,FILE*stream,string prefix){ @@ -58,21 +58,52 @@ void print(tree t,FILE*stream,string prefix){
58 //needs to check stream!=NULL 58 //needs to check stream!=NULL
59 if(is_empty(t)) 59 if(is_empty(t))
60 return; 60 return;
  61 +
  62 + string word=calloc((strlen(prefix)+2),sizeof(char));
  63 + strcpy(word,prefix);
  64 + strncat(word,&(t->letter),1);
  65 +
61 if(is_end(t)){ 66 if(is_end(t)){
62 - if(is_acronyme_end(t)){  
63 - if(is_straight_end(t)){}  
64 - else{} 67 + string word2=calloc((strlen(prefix)+4),sizeof(char));
  68 + strcpy(word2,word);
  69 + //common_end
  70 + if(is_common_end(t)){
  71 + if(is_straight_end(t)){
  72 + printf("%s\n",word2);
  73 + }
  74 + if(ends_with_apostrophe(t)){
  75 + printf("%s's\n",word2);
  76 + }
65 } 77 }
  78 + //proper_end
66 if(is_proper_end(t)){ 79 if(is_proper_end(t)){
67 - if(is_straight_end(t)){}  
68 - else{} 80 + word2[0]=toupper(word2[0]);
  81 + if(is_straight_end(t)){
  82 + printf("%s\n",word2);
  83 + }
  84 + if(ends_with_apostrophe(t)){
  85 + printf("%s's\n",word2);
  86 + }
69 } 87 }
70 - if(is_common_end(t)){  
71 - if(is_straight_end(t)){}  
72 - else{} 88 + //acronyme_end
  89 + if(is_acronyme_end(t)){
  90 + strupper(word2);
  91 + if(is_straight_end(t)){
  92 + printf("%s\n",word2);
  93 + }
  94 + if(ends_with_apostrophe(t)){
  95 + printf("%s's\n",word2);
  96 + }
73 } 97 }
  98 + free(word2);
74 } 99 }
75 for(int i=0;i<NBCHAR;i++){ 100 for(int i=0;i<NBCHAR;i++){
76 - print(t->next[i],stream); 101 + print(t->next[i],stream,word);
77 } 102 }
  103 + free(word);
  104 +}
  105 +
  106 +void strupper(string str){
  107 + for(int i=0;str[i]!='\0';i++)
  108 + str[i]=toupper(str[i]);
78 } 109 }
@@ -15,6 +15,9 @@ void loadfrom_keyboard(dico);//i.e. loadfrom_file(dico,stdin); @@ -15,6 +15,9 @@ void loadfrom_keyboard(dico);//i.e. loadfrom_file(dico,stdin);
15 15
16 void printto_file(dico,FILE*); 16 void printto_file(dico,FILE*);
17 void printto_terminal(dico);//i.e. printto_file(dico,stdout); 17 void printto_terminal(dico);//i.e. printto_file(dico,stdout);
18 -void print(tree,FILE*,string) 18 +void print(tree,FILE*,string);
  19 +
  20 +void strupper(string str);
  21 +
19 22
20 #endif 23 #endif
@@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
5 #include <stdio.h> 5 #include <stdio.h>
6 #include <string.h> 6 #include <string.h>
7 #include <stdbool.h> 7 #include <stdbool.h>
  8 +#include <ctype.h>
8 9
9 #define NBCHAR 26 //A-Z 10 #define NBCHAR 26 //A-Z
10 11