Commit 4d76adf02b3001ba02cb2cb6c9c23a5a889f4162
1 parent
2934aea8
nouvelle version mais avec quelque erreur
Showing
3 changed files
with
211 additions
and
0 deletions
Show diff stats
ima3_projet_pa_2019 @ 3d38a257c3d
... | ... | @@ -0,0 +1 @@ |
1 | +Subproject commit 3d38a257c3d7d05230a85387666591b5a33a973d | ... | ... |
... | ... | @@ -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 | +} | ... | ... |
... | ... | @@ -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 | +} | ... | ... |