Blame view

projetV2.c 5.62 KB
327fa977   mduquesn   final
1
  <<<<<<< HEAD
28ae80ee   mduquesn   final
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
  #include <stdio.h>

  #include <string.h>

  #include <stdlib.h>

  #include <stdbool.h>

  

  struct cell {

    int stop;

    struct cell * liste[26];

  };

  

  int num(char c){

    int x;

    x=c;

    if (x>96 && x<123){

      x=x-97;

    return x;

    }

    if (x>64 && x<91) {

      x=x-65;

    return x;

    }

    printf("erreur num \n");

    return -1;

  }

  

  int ajout_mot(struct cell ** d,char * m){

    char c;

    struct cell **tmp1 , *tmp2 ;

    int x=0;

    if (*d==NULL){return 0;}

    tmp1=d;

    c=m[x];

    while (c != '\0'){

      //printf("%c",c);

      if ((*tmp1)->liste[num(c)]==NULL){

        tmp2=malloc(sizeof(struct cell));

        (*tmp1)->liste[num(c)]=tmp2;

      }

      tmp1=&((*tmp1)->liste[num(c)]);

      x++;

      c=m[x];

    }

    (*tmp1)->stop=1;

    //printf("\n");

    return 1;

  }

  

  int creation_dico(FILE *fd, struct cell **d){

    char s[20];

    while (fscanf(fd,"%s",s)==1){

      if (ajout_mot(d,s)==0){return 0;}

    }

  return 1;

  }

  

  int fin_mot(char c){

     if ((c>64 && c<91)||(c>96 && c<123)){

       return 0;}

     return 1;

  }

  

  int comparaison(char *m , int x , int conjug){

    if (fin_mot(m[x])==1){

      return 1;

    }

    if (conjug==1){

      if (fin_mot(m[x+1])==1 && m[x]=='s'){

        return 1;

      }

      if (fin_mot(m[x+2])==1 && m[x+1]=='d' && m[x]=='e'){

        return 1;

      }

      if (fin_mot(m[x+3])==1 && m[x+2]=='g' && m[x+1]=='n' && m[x]=='i'){

        return 1;

      }

    }

    return 0;

  }

  

  int reconaissance(struct cell * d,char * m){

    char c;

    struct cell *tmp1;

    int x=0;

    tmp1=d;

    if (d==NULL){return 1;}

    c=m[x];

    while (comparaison (m,x,1) == 0 ){

      if (tmp1->liste[num(c)]==NULL){return 1;}

      tmp1=(tmp1->liste[num(c)]);

      x++;

      c=m[x];    

    }

    if (tmp1->stop==1) {return 0;}

    return 1;

  }

  

  int lecture(FILE *fd, struct cell *d){

    char s[20];

    int cmpt=0;

    int x;

    while (fscanf(fd,"%s",s)==1){

      x=reconaissance(d,s);

      cmpt+=x;

      if(x==1){printf("%s \n",s);}

    }

    return cmpt;

  }

  

  void suprime_dico(struct cell **d){

    int i=0;

    for (i=0;i<26;i++){

      if ((*d)->liste[i]!=NULL){

        suprime_dico(&((*d)->liste[i]));

      }

    }

    free(*d);

  }

  

  

  int main(int argc, char *argv[])

  {

  	if (argc < 3)

  	{

  		fprintf(stderr, "usage: hash <file_name>\n");

  		return EXIT_FAILURE;

  	}

  

  	FILE *fp;

  	printf("%s\n",argv[1]);

  	fp=fopen(argv[1], "r");

  	if (fp==NULL)

  	{

  		fprintf(stderr, "no such file, or unreachable: %s\n", argv[1]);

  		return EXIT_FAILURE;

  	}

  	

  	FILE *fd;

  	printf("%s\n",argv[2]);

  	fd=fopen(argv[2], "r");

  	if (fd==NULL)

  	{

  		fprintf(stderr, "no such file, or unreachable: %s\n", argv[2]);

  		return EXIT_FAILURE;

  	}

  

  	

  	struct cell *d;

  	d=malloc(sizeof(struct cell));

  	creation_dico(fp,&d);

  	int inc;

  	inc=lecture(fd,d);

  	printf("%d mots non reconnus \n", inc);

  	suprime_dico(&d);

  	free(fd);

  	free(fp);

  	return 1;

  }

327fa977   mduquesn   final
159
160
  ||||||| merged common ancestors
  =======
8af1f242   mduquesn   V2
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
  #include <stdio.h>
  #include <string.h>
  #include <stdlib.h>
  #include <stdbool.h>
  
  struct cell {
    int stop;
    struct cell * liste[26];
  };
  
  int num(char c){
    int x;
    x=c;
    if (x>96 && x<123){
      x=x-97;
    return x;
    }
    if (x>64 && x<91) {
      x=x-65;
    return x;
    }
    printf("erreur num \n");
    return -1;
  }
  
  int ajout_mot(struct cell ** d,char * m){
    char c;
    struct cell **tmp1 , *tmp2 ;
    int x=0;
    if (*d==NULL){return EXIT_FAILURE;}
    tmp1=d;
    c=m[x];
    while (c != '\0'){
      //printf("%c",c);
      if ((*tmp1)->liste[num(c)]==NULL){
        tmp2=malloc(sizeof(struct cell));
        (*tmp1)->liste[num(c)]=tmp2;
      }
      tmp1=&((*tmp1)->liste[num(c)]);
      x++;
      c=m[x];
    }
    (*tmp1)->stop=1;
    //printf("\n");
    return 1;
  }
  
  void creation_dico(FILE *fd, struct cell **d){
    char s[20];
    while (fscanf(fd,"%s",s)==1){
      ajout_mot(d,s);
    }
  }
  
  int fin_mot(char c){
     if (c == '\0' || c == ' ' || c== '.' || c == ':' || c == ',' || c == '?' || c == ';'  || c == '\'' || c == '\"' || c == '!' || c == '`' || c == '-' || c == '_'){
       return 1;}
     return 0;
  }
  
  int comparaison(char *m , int x , int conjug){
    if (fin_mot(m[x])==1){
      return 1;
    }
    if (conjug==1){
      if (fin_mot(m[x+1])==1 && m[x]=='s'){
        return 1;
      }
      if (fin_mot(m[x+2])==1 && m[x+1]=='d' && m[x]=='e'){
        return 1;
      }
      if (fin_mot(m[x+3])==1 && m[x+2]=='g' && m[x+1]=='n' && m[x]=='i'){
        return 1;
      }
    }
    return 0;
  }
  
  int reconaissance(struct cell * d,char * m){
    char c;
    struct cell *tmp1;
    int x=0;
    tmp1=d;
    if (d==NULL){return 1;}
    c=m[x];
    while (comparaison (m,x,1) == 0 ){
      if (tmp1->liste[num(c)]==NULL){return 1;}
      tmp1=(tmp1->liste[num(c)]);
      x++;
      c=m[x];    
    }
    if (tmp1->stop==1) {return 0;}
    return 1;
  }
  
  int lecture(FILE *fd, struct cell *d){
    char s[20];
    int cmpt=0;
    int x;
    while (fscanf(fd,"%s",s)==1){
      x=reconaissance(d,s);
      cmpt+=x;
      if(x==1){printf("%s \n",s);}
    }
    return cmpt;
  }
  
  void suprime_dico(struct cell **d){
    int i=0;
    for (i=0;i<26;i++){
      if ((*d)->liste[i]!=NULL){
        suprime_dico(&((*d)->liste[i]));
      }
    }
    free(*d);
  }
  
  
  int main(int argc, char *argv[])
  {
  	if (argc < 3)
  	{
  		fprintf(stderr, "usage: hash <file_name>\n");
  		return EXIT_FAILURE;
  	}
  
  	FILE *fp;
  	printf("%s\n",argv[1]);
  	fp=fopen(argv[1], "r");
  	if (fp==NULL)
  	{
  		fprintf(stderr, "no such file, or unreachable: %s\n", argv[1]);
  		return EXIT_FAILURE;
  	}
  	
  	FILE *fd;
  	printf("%s\n",argv[2]);
  	fd=fopen(argv[2], "r");
  	if (fd==NULL)
  	{
  		fprintf(stderr, "no such file, or unreachable: %s\n", argv[2]);
  		return EXIT_FAILURE;
  	}
  
  	
  	struct cell *d;
  	d=malloc(sizeof(struct cell));
  	creation_dico(fp,&d);
  	int inc;
  	inc=lecture(fd,d);
  	printf("%d mots non reconnus \n", inc);
  	suprime_dico(&d);
  	free(fd);
  	free(fp);
  }
327fa977   mduquesn   final
316
  >>>>>>> 8af1f2429503e7afb5adcccb10b4548b1dc0e101