Commit 327fa97706edee0e5f44d1746955179dc885dc57
final
Showing
3 changed files
with
369 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,64 @@ | @@ -0,0 +1,64 @@ | ||
1 | +#include <stdio.h> | ||
2 | +#include <string.h> | ||
3 | +#include <stdlib.h> | ||
4 | +#include <stdbool.h> | ||
5 | + | ||
6 | +struct cell { | ||
7 | + int stop; | ||
8 | + struct cell * liste[26]; | ||
9 | +}; | ||
10 | + | ||
11 | +int num(char c){ | ||
12 | + return 1; | ||
13 | +} | ||
14 | + | ||
15 | +int ajout_mot(struct cell ** d,char * m){ | ||
16 | + char c; | ||
17 | + struct cell **tmp1 , *tmp2 ; | ||
18 | + int x=0; | ||
19 | + if (*d==NULL){return EXIT_FAILURE;} | ||
20 | + tmp1=d; | ||
21 | + c=m[x]; | ||
22 | + while (c!="\0"){ | ||
23 | + printf("%c",c); | ||
24 | + if ((*tmp1)->liste[num(c)]==NULL){ | ||
25 | + tmp2=malloc(sizeof(struct cell)); | ||
26 | + (*tmp1)->liste[num(c)]=tmp2; | ||
27 | + } | ||
28 | + tmp1=&((*tmp1)->liste[num(c)]); | ||
29 | + x++; | ||
30 | + c=m[x]; | ||
31 | + } | ||
32 | + return 1; | ||
33 | +} | ||
34 | + | ||
35 | +void creation_dico(FILE *fd,struct cell **d){ | ||
36 | + char s[20]; | ||
37 | + while (fscanf(fd,"%s",s)==1){ | ||
38 | + ajout_mot(d,s); | ||
39 | + } | ||
40 | +} | ||
41 | + | ||
42 | +int main(int argc, char *argv[]) | ||
43 | +{ | ||
44 | + if (argc < 2) | ||
45 | + { | ||
46 | + fprintf(stderr, "usage: hash <file_name>\n"); | ||
47 | + return EXIT_FAILURE; | ||
48 | + } | ||
49 | + | ||
50 | + FILE *fp; | ||
51 | + printf("%s\n",argv[1]); | ||
52 | + fp=fopen(argv[1], "r"); | ||
53 | + if (fp==NULL) | ||
54 | + { | ||
55 | + fprintf(stderr, "no such file, or unreachable: %s\n", argv[1]); | ||
56 | + return EXIT_FAILURE; | ||
57 | + } | ||
58 | + struct cell *d; | ||
59 | + d=malloc(sizeof(struct cell)); | ||
60 | + //creation_dico(fp,&d); | ||
61 | + char s[]="helo\0"; | ||
62 | + ajout_mot(&d,s); | ||
63 | + | ||
64 | +} |
projetV2.c
1 | +<<<<<<< HEAD | ||
1 | #include <stdio.h> | 2 | #include <stdio.h> |
2 | #include <string.h> | 3 | #include <string.h> |
3 | #include <stdlib.h> | 4 | #include <stdlib.h> |
@@ -155,3 +156,161 @@ int main(int argc, char *argv[]) | @@ -155,3 +156,161 @@ int main(int argc, char *argv[]) | ||
155 | free(fp); | 156 | free(fp); |
156 | return 1; | 157 | return 1; |
157 | } | 158 | } |
159 | +||||||| merged common ancestors | ||
160 | +======= | ||
161 | +#include <stdio.h> | ||
162 | +#include <string.h> | ||
163 | +#include <stdlib.h> | ||
164 | +#include <stdbool.h> | ||
165 | + | ||
166 | +struct cell { | ||
167 | + int stop; | ||
168 | + struct cell * liste[26]; | ||
169 | +}; | ||
170 | + | ||
171 | +int num(char c){ | ||
172 | + int x; | ||
173 | + x=c; | ||
174 | + if (x>96 && x<123){ | ||
175 | + x=x-97; | ||
176 | + return x; | ||
177 | + } | ||
178 | + if (x>64 && x<91) { | ||
179 | + x=x-65; | ||
180 | + return x; | ||
181 | + } | ||
182 | + printf("erreur num \n"); | ||
183 | + return -1; | ||
184 | +} | ||
185 | + | ||
186 | +int ajout_mot(struct cell ** d,char * m){ | ||
187 | + char c; | ||
188 | + struct cell **tmp1 , *tmp2 ; | ||
189 | + int x=0; | ||
190 | + if (*d==NULL){return EXIT_FAILURE;} | ||
191 | + tmp1=d; | ||
192 | + c=m[x]; | ||
193 | + while (c != '\0'){ | ||
194 | + //printf("%c",c); | ||
195 | + if ((*tmp1)->liste[num(c)]==NULL){ | ||
196 | + tmp2=malloc(sizeof(struct cell)); | ||
197 | + (*tmp1)->liste[num(c)]=tmp2; | ||
198 | + } | ||
199 | + tmp1=&((*tmp1)->liste[num(c)]); | ||
200 | + x++; | ||
201 | + c=m[x]; | ||
202 | + } | ||
203 | + (*tmp1)->stop=1; | ||
204 | + //printf("\n"); | ||
205 | + return 1; | ||
206 | +} | ||
207 | + | ||
208 | +void creation_dico(FILE *fd, struct cell **d){ | ||
209 | + char s[20]; | ||
210 | + while (fscanf(fd,"%s",s)==1){ | ||
211 | + ajout_mot(d,s); | ||
212 | + } | ||
213 | +} | ||
214 | + | ||
215 | +int fin_mot(char c){ | ||
216 | + if (c == '\0' || c == ' ' || c== '.' || c == ':' || c == ',' || c == '?' || c == ';' || c == '\'' || c == '\"' || c == '!' || c == '`' || c == '-' || c == '_'){ | ||
217 | + return 1;} | ||
218 | + return 0; | ||
219 | +} | ||
220 | + | ||
221 | +int comparaison(char *m , int x , int conjug){ | ||
222 | + if (fin_mot(m[x])==1){ | ||
223 | + return 1; | ||
224 | + } | ||
225 | + if (conjug==1){ | ||
226 | + if (fin_mot(m[x+1])==1 && m[x]=='s'){ | ||
227 | + return 1; | ||
228 | + } | ||
229 | + if (fin_mot(m[x+2])==1 && m[x+1]=='d' && m[x]=='e'){ | ||
230 | + return 1; | ||
231 | + } | ||
232 | + if (fin_mot(m[x+3])==1 && m[x+2]=='g' && m[x+1]=='n' && m[x]=='i'){ | ||
233 | + return 1; | ||
234 | + } | ||
235 | + } | ||
236 | + return 0; | ||
237 | +} | ||
238 | + | ||
239 | +int reconaissance(struct cell * d,char * m){ | ||
240 | + char c; | ||
241 | + struct cell *tmp1; | ||
242 | + int x=0; | ||
243 | + tmp1=d; | ||
244 | + if (d==NULL){return 1;} | ||
245 | + c=m[x]; | ||
246 | + while (comparaison (m,x,1) == 0 ){ | ||
247 | + if (tmp1->liste[num(c)]==NULL){return 1;} | ||
248 | + tmp1=(tmp1->liste[num(c)]); | ||
249 | + x++; | ||
250 | + c=m[x]; | ||
251 | + } | ||
252 | + if (tmp1->stop==1) {return 0;} | ||
253 | + return 1; | ||
254 | +} | ||
255 | + | ||
256 | +int lecture(FILE *fd, struct cell *d){ | ||
257 | + char s[20]; | ||
258 | + int cmpt=0; | ||
259 | + int x; | ||
260 | + while (fscanf(fd,"%s",s)==1){ | ||
261 | + x=reconaissance(d,s); | ||
262 | + cmpt+=x; | ||
263 | + if(x==1){printf("%s \n",s);} | ||
264 | + } | ||
265 | + return cmpt; | ||
266 | +} | ||
267 | + | ||
268 | +void suprime_dico(struct cell **d){ | ||
269 | + int i=0; | ||
270 | + for (i=0;i<26;i++){ | ||
271 | + if ((*d)->liste[i]!=NULL){ | ||
272 | + suprime_dico(&((*d)->liste[i])); | ||
273 | + } | ||
274 | + } | ||
275 | + free(*d); | ||
276 | +} | ||
277 | + | ||
278 | + | ||
279 | +int main(int argc, char *argv[]) | ||
280 | +{ | ||
281 | + if (argc < 3) | ||
282 | + { | ||
283 | + fprintf(stderr, "usage: hash <file_name>\n"); | ||
284 | + return EXIT_FAILURE; | ||
285 | + } | ||
286 | + | ||
287 | + FILE *fp; | ||
288 | + printf("%s\n",argv[1]); | ||
289 | + fp=fopen(argv[1], "r"); | ||
290 | + if (fp==NULL) | ||
291 | + { | ||
292 | + fprintf(stderr, "no such file, or unreachable: %s\n", argv[1]); | ||
293 | + return EXIT_FAILURE; | ||
294 | + } | ||
295 | + | ||
296 | + FILE *fd; | ||
297 | + printf("%s\n",argv[2]); | ||
298 | + fd=fopen(argv[2], "r"); | ||
299 | + if (fd==NULL) | ||
300 | + { | ||
301 | + fprintf(stderr, "no such file, or unreachable: %s\n", argv[2]); | ||
302 | + return EXIT_FAILURE; | ||
303 | + } | ||
304 | + | ||
305 | + | ||
306 | + struct cell *d; | ||
307 | + d=malloc(sizeof(struct cell)); | ||
308 | + creation_dico(fp,&d); | ||
309 | + int inc; | ||
310 | + inc=lecture(fd,d); | ||
311 | + printf("%d mots non reconnus \n", inc); | ||
312 | + suprime_dico(&d); | ||
313 | + free(fd); | ||
314 | + free(fp); | ||
315 | +} | ||
316 | +>>>>>>> 8af1f2429503e7afb5adcccb10b4548b1dc0e101 |
@@ -0,0 +1,146 @@ | @@ -0,0 +1,146 @@ | ||
1 | +#include <stdio.h> | ||
2 | +#include <string.h> | ||
3 | +#include <stdlib.h> | ||
4 | +#include <stdbool.h> | ||
5 | + | ||
6 | +struct cell { | ||
7 | + int stop; | ||
8 | + struct cell * liste[26]; | ||
9 | +}; | ||
10 | + | ||
11 | +int num(char c){ | ||
12 | + int x; | ||
13 | + x=c; | ||
14 | + if (x>96 && x<123){x=x-97;} | ||
15 | + if (x>64 && x<91) {x=x-65;} | ||
16 | + return x; | ||
17 | +} | ||
18 | + | ||
19 | +int ajout_mot(struct cell ** d,char * m){ | ||
20 | + char c; | ||
21 | + struct cell **tmp1 , *tmp2 ; | ||
22 | + int x=0; | ||
23 | + if (*d==NULL){return EXIT_FAILURE;} | ||
24 | + tmp1=d; | ||
25 | + c=m[x]; | ||
26 | + while (c != '\0'){ | ||
27 | + //printf("%c",c); | ||
28 | + if ((*tmp1)->liste[num(c)]==NULL){ | ||
29 | + tmp2=malloc(sizeof(struct cell)); | ||
30 | + (*tmp1)->liste[num(c)]=tmp2; | ||
31 | + } | ||
32 | + tmp1=&((*tmp1)->liste[num(c)]); | ||
33 | + x++; | ||
34 | + c=m[x]; | ||
35 | + } | ||
36 | + (*tmp1)->stop=1; | ||
37 | + //printf("\n"); | ||
38 | + return 1; | ||
39 | +} | ||
40 | + | ||
41 | +void creation_dico(FILE *fd, struct cell **d){ | ||
42 | + char s[20]; | ||
43 | + while (fscanf(fd,"%s",s)==1){ | ||
44 | + ajout_mot(d,s); | ||
45 | + } | ||
46 | +} | ||
47 | + | ||
48 | +int fin_mot(char c){ | ||
49 | + if (c == '\0' || c == ' ' || c== '.' || c == ':' || c == ',' || c == '?' || c == ';'){ | ||
50 | + return 1;} | ||
51 | + return 0; | ||
52 | +} | ||
53 | + | ||
54 | +int comparaison(char *m , int x , int conjug){ | ||
55 | + if (fin_mot(m[x])==1){ | ||
56 | + return 1; | ||
57 | + } | ||
58 | + if (conjug==1){ | ||
59 | + if (fin_mot(m[x+1])==1 && m[x]=='s'){ | ||
60 | + return 1; | ||
61 | + } | ||
62 | + if (fin_mot(m[x+2])==1 && m[x+1]=='d' && m[x]=='e'){ | ||
63 | + return 1; | ||
64 | + } | ||
65 | + if (fin_mot(m[x+3])==1 && m[x+2]=='g' && m[x+1]=='n' && m[x]=='i'){ | ||
66 | + return 1; | ||
67 | + } | ||
68 | + } | ||
69 | + return 0; | ||
70 | +} | ||
71 | + | ||
72 | +int reconaissance(struct cell * d,char * m){ | ||
73 | + char c; | ||
74 | + struct cell *tmp1; | ||
75 | + int x=0; | ||
76 | + tmp1=d; | ||
77 | + if (d==NULL){return 1;} | ||
78 | + c=m[x]; | ||
79 | + while (comparaison (m,x,1) == 0 ){ | ||
80 | + if (tmp1->liste[num(c)]==NULL){return 1;} | ||
81 | + tmp1=(tmp1->liste[num(c)]); | ||
82 | + x++; | ||
83 | + c=m[x]; | ||
84 | + } | ||
85 | + if (tmp1->stop==1) {return 0;} | ||
86 | + return 1; | ||
87 | +} | ||
88 | + | ||
89 | +int lecture(FILE *fd, struct cell *d){ | ||
90 | + char s[20]; | ||
91 | + int cmpt=0; | ||
92 | + int x; | ||
93 | + while (fscanf(fd,"%s",s)==1){ | ||
94 | + x=reconaissance(d,s); | ||
95 | + cmpt+=x; | ||
96 | + if(x==1){printf("%s \n",s);} | ||
97 | + } | ||
98 | + return cmpt; | ||
99 | +} | ||
100 | + | ||
101 | +void suprime_dico(struct cell **d){ | ||
102 | + int i=0; | ||
103 | + for (i=0;i<26;i++){ | ||
104 | + if ((*d)->liste[i]!=NULL){ | ||
105 | + suprime_dico(&((*d)->liste[i])); | ||
106 | + } | ||
107 | + } | ||
108 | + free(*d); | ||
109 | +} | ||
110 | + | ||
111 | + | ||
112 | +int main(int argc, char *argv[]) | ||
113 | +{ | ||
114 | + if (argc < 3) | ||
115 | + { | ||
116 | + fprintf(stderr, "usage: hash <file_name>\n"); | ||
117 | + return EXIT_FAILURE; | ||
118 | + } | ||
119 | + | ||
120 | + FILE *fp; | ||
121 | + printf("%s\n",argv[1]); | ||
122 | + fp=fopen(argv[1], "r"); | ||
123 | + if (fp==NULL) | ||
124 | + { | ||
125 | + fprintf(stderr, "no such file, or unreachable: %s\n", argv[1]); | ||
126 | + return EXIT_FAILURE; | ||
127 | + } | ||
128 | + | ||
129 | + FILE *fd; | ||
130 | + printf("%s\n",argv[2]); | ||
131 | + fd=fopen(argv[2], "r"); | ||
132 | + if (fd==NULL) | ||
133 | + { | ||
134 | + fprintf(stderr, "no such file, or unreachable: %s\n", argv[2]); | ||
135 | + return EXIT_FAILURE; | ||
136 | + } | ||
137 | + | ||
138 | + | ||
139 | + struct cell *d; | ||
140 | + d=malloc(sizeof(struct cell)); | ||
141 | + creation_dico(fp,&d); | ||
142 | + int inc; | ||
143 | + inc=lecture(fd,d); | ||
144 | + printf("%d mots non reconnus \n", inc); | ||
145 | + suprime_dico(&d); | ||
146 | +} |