Commit f5270af0707f4e5f0830191d542a67bd487f152b
1 parent
af1143d1
projet
Showing
1 changed file
with
87 additions
and
39 deletions
Show diff stats
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <stdio.h> | 2 | #include <stdio.h> |
3 | #include <string.h> | 3 | #include <string.h> |
4 | -#define size 50 | ||
5 | -#define taille 26 | 4 | +#include <ctype.h> |
5 | +#define size 128 | ||
6 | 6 | ||
7 | -struct noeud { char valeur; struct noeud * fils[28]; int complet;}; | ||
8 | -struct dico {struct noeud* tableau[26];}; | 7 | +int alphabet[27] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',39 }; |
8 | + | ||
9 | +struct noeud { char valeur; struct noeud * fils[27]; int complet;}; | ||
10 | +struct dico {struct noeud* tableau[26];}; int i; | ||
9 | typedef struct noeud* Noeud; | 11 | typedef struct noeud* Noeud; |
10 | 12 | ||
11 | 13 | ||
12 | -void cons_noeud (Noeud * pN, char a) | 14 | +Noeud cons_noeud (char a) |
13 | { | 15 | { |
14 | - *pN = malloc(sizeof(struct noeud)); | ||
15 | - (*pN)->valeur=a; | ||
16 | - (*pN)->complet=0; | 16 | + Noeud pN = malloc(sizeof(struct noeud)); |
17 | + (*pN).valeur=a; | ||
18 | + (*pN).complet=0; | ||
17 | for(int i=0; i<28; i++) | 19 | for(int i=0; i<28; i++) |
18 | { | 20 | { |
19 | - (*pN)->fils[i]=NULL; | 21 | + (*pN).fils[i]=NULL; |
20 | } | 22 | } |
23 | + return pN; | ||
21 | } | 24 | } |
22 | 25 | ||
23 | void ajout_noeud_dico(struct dico * D, Noeud N) | 26 | void ajout_noeud_dico(struct dico * D, Noeud N) |
@@ -28,79 +31,123 @@ void ajout_noeud_dico(struct dico * D, Noeud N) | @@ -28,79 +31,123 @@ void ajout_noeud_dico(struct dico * D, Noeud N) | ||
28 | D->tableau[i]=N; | 31 | D->tableau[i]=N; |
29 | } | 32 | } |
30 | 33 | ||
31 | -void ajout_mot(Noeud * pN, char mot[size]) | 34 | +//tolower --> fonction qui prend une lettre quelconque en argument et renvoie son équivalent en miniscule |
35 | + | ||
36 | +/*void ajout_mot_noeud(Noeud * pN, char mot[size]) | ||
32 | { | 37 | { |
38 | + int j=0; | ||
39 | + int n=strlen(mot); | ||
33 | if(*pN==NULL) | 40 | if(*pN==NULL) |
34 | { | 41 | { |
35 | - cons_noeud(pN,mot[0]); | ||
36 | - sup_lettre(mot); | 42 | + *pN=cons_noeud(tolower(mot[0])); |
43 | + *pN=(*pN)->fils[j]; | ||
37 | } | 44 | } |
38 | - else | ||
39 | - | ||
40 | -} | 45 | + *pN=(*pN)->fils[j]; |
46 | + printf("%d\n",j); | ||
47 | + for(int i=1; i<n; i++) | ||
48 | + { | ||
49 | + while((*pN)!=NULL && tolower((*pN)->valeur)!= tolower(mot[i])) | ||
50 | + {j++;} | ||
51 | + if(j==0) | ||
52 | + { | ||
53 | + *pN= (*pN)->fils[j+1]; | ||
54 | + } | ||
55 | + else if (*pN == NULL) | ||
56 | + { | ||
57 | + *pN =cons_noeud(tolower(mot[i])); | ||
58 | + *pN= (*pN)->fils[j]; | ||
59 | + } | ||
60 | + } | ||
61 | + (*pN)->complet=1; | ||
62 | +}*/ | ||
41 | 63 | ||
42 | -char * sup_lettre(char mot[size]) | 64 | +void ajout_mot_noeud(Noeud * pN, char mot[size]) |
43 | { | 65 | { |
44 | - for(int i=1; i<size; i++) | 66 | + int i,n=strlen(mot); |
67 | + if(& (*pN)->valeur==NULL) | ||
68 | + *pN = cons_noeud(tolower(mot[0])); | ||
69 | + for(i=1;i<n;i++) | ||
45 | { | 70 | { |
46 | - mot[i]= mot[i+1]; | ||
47 | - } | ||
48 | - printf("%s\n",mot); | 71 | + pN=&(*pN)->alphabet[tolower(mot[i])-'a']; |
72 | + if(&(*pN)->valeur==NULL) | ||
73 | + *pN= cons_noeud(tolower(mot[i])); | ||
74 | + } | ||
75 | + (*pN)->complet=1; | ||
49 | } | 76 | } |
50 | 77 | ||
51 | -//Reprendre cette fonction! | 78 | +//Reprendre cette fonction! ; |
79 | + | ||
52 | 80 | ||
53 | /*void cons_dico_file(FILE* fp, struct dico* D) | 81 | /*void cons_dico_file(FILE* fp, struct dico* D) |
54 | { char mot[size]; | 82 | { char mot[size]; |
55 | if(fp==NULL) | 83 | if(fp==NULL) |
56 | return; | 84 | return; |
57 | - while(fscanf(fp,"%s",a)==1) | 85 | + while(fscanf(fp,"%s",a)==1)*pN=NULL; |
58 | { ajout_mot(D,a); | 86 | { ajout_mot(D,a); |
59 | - //D->dernier++;} | 87 | + //D->dernier++;} //int i=O; |
60 | 88 | ||
61 | }*/ | 89 | }*/ |
62 | 90 | ||
91 | + | ||
63 | /*int rech_mot(struct dico D,char mot [size]) | 92 | /*int rech_mot(struct dico D,char mot [size]) |
64 | -{ | ||
65 | - Noeud N; | 93 | +{ char * mot; |
94 | + mot=sup_lettre("emilie");N)->fils[j]!=NULL || (*pN)->fils[j]->valeur!= mot[i+1]) //int i=O; | ||
95 | + {j++;} | ||
96 | + printf("%s\n",mot); | ||
97 | + Noeud N; //int i=O; | ||
66 | int nbre; | 98 | int nbre; |
67 | for(int i=0;i<D.dernier;i++) | 99 | for(int i=0;i<D.dernier;i++) |
68 | { | 100 | { |
69 | if(D.tableau[i].valeur==mot[0]) | 101 | if(D.tableau[i].valeur==mot[0]) |
70 | - { | 102 | + { char * mot; //int i=O; |
103 | + mot=sup_lettre("emilie"); | ||
104 | + printf("%s\n",mot); | ||
71 | N=D.tableau[i]; | 105 | N=D.tableau[i]; |
72 | for(int j=0;j<size;j++) | 106 | for(int j=0;j<size;j++) |
73 | - { | 107 | + { //int i=O; |
74 | if(N.valeur==mot[j]) | 108 | if(N.valeur==mot[j]) |
75 | N=*(N.fils)->noeud; | 109 | N=*(N.fils)->noeud; |
76 | - else | 110 | + else //int i=O; |
77 | nbre=0; | 111 | nbre=0; |
78 | } | 112 | } |
79 | - if(N.complet==1)return newmot | ||
80 | - nbre=1; | 113 | + if(N.complet==1)return newmot //int i=O; |
114 | + nbre=1;N)->fils[j]!=NULL || (*pN)->fils[j]->valeur!= mot[i+1]) //int i=O; | ||
115 | + {j++;} | ||
81 | } | 116 | } |
82 | - else | 117 | + else char * mot; |
118 | + mot=sup_lettre("emilie"); //int i=O; | ||
119 | + printf("%s\n",mot); | ||
83 | nbre= 0; | 120 | nbre= 0; |
84 | } | 121 | } |
85 | - return nbre; | 122 | + return nbre; //int i=O; |
86 | }*/ | 123 | }*/ |
87 | 124 | ||
88 | 125 | ||
89 | /*void correction_texte(char filename[size], struct dico D) | 126 | /*void correction_texte(char filename[size], struct dico D) |
90 | { | 127 | { |
91 | FILE *fp=fopen(filename, "r"); | 128 | FILE *fp=fopen(filename, "r"); |
92 | - char mot[size]; | ||
93 | - int x; | 129 | + char mot[size]; //int i=O; |
130 | + int x; char * mot; | ||
131 | +} | ||
132 | + mot=sup_lettre("emilie"); | ||
133 | + printf("%s\n",mot); | ||
94 | if(fp==NULL)return newmot | 134 | if(fp==NULL)return newmot |
95 | return; | 135 | return; |
96 | - else | 136 | + else //int i=O; |
97 | { | 137 | { |
138 | + for(int i=1; i<size; i++) | ||
139 | + { | ||
140 | + mot[i]= newmot[i-1]; | ||
141 | + } //int i=O; | ||
98 | while(fscanf(fp,"%s",mot)==1) | 142 | while(fscanf(fp,"%s",mot)==1) |
99 | { | 143 | { |
100 | x=rech_mot(D,mot); | 144 | x=rech_mot(D,mot); |
101 | if(x==0) | 145 | if(x==0) |
102 | { | 146 | { |
103 | - printf("il y a une erreur!\n"); | 147 | + printf("il y a une err char * mot;N)->fils[j]!=NULL || (*pN)->fils[j]->valeur!= mot[i+1]) |
148 | + {j++;} //int i=O; | ||
149 | + mot=sup_lettre("emilie"); | ||
150 | + printf("%s\n",mot);eur!\n"); | ||
104 | printf("%s",mot); | 151 | printf("%s",mot); |
105 | } | 152 | } |
106 | } | 153 | } |
@@ -111,9 +158,10 @@ char * sup_lettre(char mot[size]) | @@ -111,9 +158,10 @@ char * sup_lettre(char mot[size]) | ||
111 | 158 | ||
112 | int main() | 159 | int main() |
113 | { | 160 | { |
114 | - char* newmot; | ||
115 | - sup_lettre("emilie"); | ||
116 | - | 161 | + Noeud pN; |
162 | + pN =cons_noeud('a'); | ||
163 | + ajout_mot_noeud(&pN,"arbre"); | ||
164 | + printf("%c\n", pN->valeur); | ||
117 | return 0; | 165 | return 0; |
118 | } | 166 | } |
119 | 167 |