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