Commit 4e00a1e4da2b28c7fcffd1823c38de1141d8d953
1 parent
5e2228dd
projet
Showing
1 changed file
with
80 additions
and
35 deletions
Show diff stats
... | ... | @@ -4,59 +4,76 @@ |
4 | 4 | #define size 50 |
5 | 5 | #define taille 26 |
6 | 6 | |
7 | -struct Noeud { char valeur;struct liste * fils; char complet;}; | |
7 | +struct Noeud { char valeur;struct liste * fils; int complet;}; | |
8 | 8 | |
9 | 9 | struct liste { struct Noeud * noeud; struct liste * suivant;}; |
10 | 10 | |
11 | 11 | struct dico {struct Noeud tableau[26];int dernier;}; |
12 | 12 | |
13 | -typedef struct liste * liste; | |
13 | +//typedef struct liste* liste; | |
14 | 14 | |
15 | 15 | typedef struct Noeud Noeud; |
16 | 16 | |
17 | 17 | |
18 | -Noeud cons_noeud (char a) | |
18 | +Noeud* cons_noeud (char a) | |
19 | 19 | { |
20 | 20 | Noeud * N = malloc(sizeof(struct Noeud)); |
21 | 21 | N->valeur=a; |
22 | 22 | N->fils=NULL; |
23 | 23 | N->complet=0; |
24 | - return * N; | |
24 | + return N; | |
25 | 25 | } |
26 | 26 | |
27 | -void ajout_lettre (Noeud * N , char a) | |
27 | +/*void ajout_lettre (Noeud * N , char a) | |
28 | 28 | { |
29 | - if(N==NULL) | |
30 | - cons_noeud(a); | |
31 | - else | |
32 | - { ((N->fils)->noeud)->valeur=a; | |
33 | - ((N->fils)->noeud)->fils=NULL; | |
29 | + if(N==NULL) | |
30 | + N=cons_noeud(a); | |
31 | + else | |
32 | + | |
33 | + ((N->fils)->noeud)->valeur=a; | |
34 | + ((N->fils)->noeud)->fils=NULL; | |
35 | + (N->fils)->suivant=NULL; | |
34 | 36 | |
35 | - } | |
36 | -} | |
37 | + | |
38 | + }*/ | |
37 | 39 | |
38 | 40 | //Reprendre cette fonction! |
39 | 41 | void ajout_mot (struct dico * D, char mot[size]) |
40 | 42 | { |
41 | 43 | Noeud *N; |
42 | - for (int j=0;j<D->dernier;j++) | |
43 | - { if(D->tableau[j].valeur== mot[0]) | |
44 | - { | |
45 | - *N=D->tableau[j]; | |
46 | - } | |
47 | - else | |
48 | - { | |
49 | - *N=cons_noeud(mot[0]); | |
50 | - } | |
44 | + int j = 0 ; | |
45 | + while (j<D->dernier && D->tableau[j].valeur != mot[0]) | |
46 | + j++ ; | |
47 | + if(j < D->dernier) | |
48 | + { | |
49 | + N=&(D->tableau[j]); | |
50 | + } | |
51 | + else | |
52 | + { | |
53 | + N=cons_noeud(mot[0]); | |
54 | + } | |
51 | 55 | |
52 | - for (int i=0; i<size; i++) | |
56 | + for (int i=1; i<size; i++) | |
53 | 57 | |
54 | - { | |
55 | - ajout_lettre (N,mot[i]); | |
58 | + { | |
59 | + if((N->fils->noeud)!=NULL) | |
60 | + { | |
61 | + N=N->fils->suivant->noeud; | |
62 | + N=cons_noeud(mot[i]); | |
63 | + //ajout_lettre(N,mot[i]); | |
64 | + } | |
65 | + else | |
66 | + { | |
56 | 67 | N=N->fils->noeud; |
68 | + N=cons_noeud(mot[i]); | |
69 | + //ajout_lettre (N,mot[i]); | |
70 | + // N=N->fils->noeud; | |
71 | + | |
57 | 72 | } |
58 | - N->complet=1; | |
59 | - } | |
73 | + | |
74 | + } | |
75 | + N->complet=1; | |
76 | + | |
60 | 77 | } |
61 | 78 | |
62 | 79 | |
... | ... | @@ -74,7 +91,7 @@ void cons_dico(FILE* fp, struct dico* D) |
74 | 91 | int rech_mot(struct dico D,char mot [size]) |
75 | 92 | { |
76 | 93 | Noeud N; |
77 | - D.dernier=-1; | |
94 | + int nbre; | |
78 | 95 | for(int i=0;i<D.dernier;i++) |
79 | 96 | { |
80 | 97 | if(D.tableau[i].valeur==mot[0]) |
... | ... | @@ -83,18 +100,46 @@ int rech_mot(struct dico D,char mot [size]) |
83 | 100 | for(int j=0;j<size;j++) |
84 | 101 | { |
85 | 102 | if(N.valeur==mot[j]) |
86 | - *N=N->fils->noeud; | |
103 | + N=*(N.fils)->noeud; | |
104 | + else | |
105 | + nbre=0; | |
87 | 106 | } |
88 | - return 1; | |
89 | - | |
90 | - if(N.complet=1) | |
91 | - return 1; | |
107 | + if(N.complet==1) | |
108 | + nbre=1; | |
92 | 109 | } |
93 | 110 | else |
94 | - return 0; | |
111 | + nbre= 0; | |
95 | 112 | } |
113 | + return nbre; | |
96 | 114 | } |
97 | 115 | |
98 | 116 | |
99 | - | |
100 | - | |
117 | +void correction_texte(char filename[size], struct dico D) | |
118 | +{ | |
119 | + FILE *fp=fopen(filename, "r"); | |
120 | + char mot[size]; | |
121 | + int x; | |
122 | + if(fp==NULL) | |
123 | + return; | |
124 | + else | |
125 | + { | |
126 | + while(fscanf(fp,"%s",mot)==1) | |
127 | + { | |
128 | + x=rech_mot(D,mot); | |
129 | + if(x==0) | |
130 | + { | |
131 | + printf("il y a une erreur!\n"); | |
132 | + printf("%s",mot); | |
133 | + } | |
134 | + } | |
135 | + } | |
136 | + | |
137 | + | |
138 | +} | |
139 | +int main(){ | |
140 | + struct dico d; | |
141 | + ajout_mot(&d,"emilie"); | |
142 | + printf( "%c",d.tableau[0].valeur); | |
143 | + return 0; | |
144 | +} | |
145 | + | ... | ... |