Commit c047868f1e800e1767b08b8d42c58a9659cf8078

Authored by mduquesn
1 parent f7bba812

old

Showing 1 changed file with 0 additions and 112 deletions   Show diff stats
projet.c deleted
... ... @@ -1,112 +0,0 @@
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 reconaissance(struct cell * d,char * m){
49   - char c;
50   - struct cell *tmp1;
51   - int x=0;
52   - tmp1=d;
53   - if (d==NULL){return 1;}
54   - c=m[x];
55   - while (c != '\0' && c != ' ' && c!= '.' && c != ':' && c != ',' && c != '?' && c != ';'){
56   - if (tmp1->liste[num(c)]==NULL){return 1;}
57   - tmp1=(tmp1->liste[num(c)]);
58   - x++;
59   - c=m[x];
60   - }
61   - if (tmp1->stop==1) {return 0;}
62   - return 1;
63   -}
64   -
65   -int lecture(FILE *fd, struct cell *d){
66   - char s[20];
67   - int cmpt=0;
68   - int x;
69   - while (fscanf(fd,"%s",s)==1){
70   - x=reconaissance(d,s);
71   - cmpt+=x;
72   - if(x==1){printf("%s \n",s);}
73   - }
74   - return cmpt;
75   -}
76   -
77   -
78   -
79   -int main(int argc, char *argv[])
80   -{
81   - if (argc < 3)
82   - {
83   - fprintf(stderr, "usage: hash <file_name>\n");
84   - return EXIT_FAILURE;
85   - }
86   -
87   - FILE *fp;
88   - printf("%s\n",argv[1]);
89   - fp=fopen(argv[1], "r");
90   - if (fp==NULL)
91   - {
92   - fprintf(stderr, "no such file, or unreachable: %s\n", argv[1]);
93   - return EXIT_FAILURE;
94   - }
95   -
96   - FILE *fd;
97   - printf("%s\n",argv[2]);
98   - fd=fopen(argv[2], "r");
99   - if (fd==NULL)
100   - {
101   - fprintf(stderr, "no such file, or unreachable: %s\n", argv[2]);
102   - return EXIT_FAILURE;
103   - }
104   -
105   -
106   - struct cell *d;
107   - d=malloc(sizeof(struct cell));
108   - creation_dico(fp,&d);
109   - int inc;
110   - inc=lecture(fd,d);
111   - printf("%d mots non reconnus", inc);
112   -}