From 4d76adf02b3001ba02cb2cb6c9c23a5a889f4162 Mon Sep 17 00:00:00 2001 From: mduquesn Date: Sat, 27 Apr 2019 17:42:02 +0200 Subject: [PATCH] nouvelle version mais avec quelque erreur --- ima3_projet_pa_2019 | 1 + projet.c~ | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ projetV2.c~ | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 211 insertions(+), 0 deletions(-) create mode 160000 ima3_projet_pa_2019 create mode 100644 projet.c~ create mode 100644 projetV2.c~ diff --git a/ima3_projet_pa_2019 b/ima3_projet_pa_2019 new file mode 160000 index 0000000..3d38a25 --- /dev/null +++ b/ima3_projet_pa_2019 @@ -0,0 +1 @@ +Subproject commit 3d38a257c3d7d05230a85387666591b5a33a973d diff --git a/projet.c~ b/projet.c~ new file mode 100644 index 0000000..9cadbd3 --- /dev/null +++ b/projet.c~ @@ -0,0 +1,64 @@ +#include +#include +#include +#include + +struct cell { + int stop; + struct cell * liste[26]; +}; + +int num(char c){ + 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]; + } + return 1; +} + +void creation_dico(FILE *fd,struct cell **d){ + char s[20]; + while (fscanf(fd,"%s",s)==1){ + ajout_mot(d,s); + } +} + +int main(int argc, char *argv[]) +{ + if (argc < 2) + { + fprintf(stderr, "usage: hash \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; + } + struct cell *d; + d=malloc(sizeof(struct cell)); + //creation_dico(fp,&d); + char s[]="helo\0"; + ajout_mot(&d,s); + +} diff --git a/projetV2.c~ b/projetV2.c~ new file mode 100644 index 0000000..bdc540e --- /dev/null +++ b/projetV2.c~ @@ -0,0 +1,146 @@ +#include +#include +#include +#include + +struct cell { + int stop; + struct cell * liste[26]; +}; + +int num(char c){ + int x; + x=c; + if (x>96 && x<123){x=x-97;} + if (x>64 && x<91) {x=x-65;} + return x; +} + +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 == ';'){ + 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 \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); +} -- libgit2 0.21.2