#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; return x; } if (x>64 && x<91) { x=x-65; return x; } printf("erreur num \n"); return -1; } struct cell * creation_cell (){ struct cell * tmp ; int i=0; tmp=malloc(sizeof(struct cell)); tmp->stop=0; for (i=0;i<26;i++){ tmp->liste[i]=NULL; } return tmp; } 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=creation_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 , int conjug){ char c; struct cell *tmp1; int x=0; tmp1=d; if (d==NULL){return 1;} c=m[x]; while (comparaison (m,x,conjug) == 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 , int conjug,int fichier){ char s[20]; int cmpt=0; int x; FILE *ff; if(fichier==1){ ff=fopen("textecorrige.txt","w"); } while (fscanf(fd,"%s",s)==1){ x=reconaissance(d,s,conjug); cmpt+=x; if(fichier==1){ if(x==1){ fprintf(ff,"!- %s -! ",s); } else{ fprintf(ff,"%s ",s); } } if(x==1){printf("%s \n",s);} } if (fichier==1){ fclose(ff); } 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; int conjug; int fichier; printf("Voulez vous prendre en compte la conjuguaison ? (fonction encore au stade expérimental) \n oui 1 , non 0 \n"); scanf("%d",&conjug); printf("Voulez vous crée un fichier txt contenant votre texte mais avec les mots non reconnue surligné ?\n oui 1 , non 0 \n"); scanf("%d",&fichier); inc=lecture(fd,d,conjug,fichier); printf(" %d mots non reconnus \n ", inc); suprime_dico(&d); fclose(fd); fclose(fp); return 0; }