diff --git a/projetfinal/projet.c b/projetfinal/projet.c new file mode 100644 index 0000000..7e7249b --- /dev/null +++ b/projetfinal/projet.c @@ -0,0 +1,154 @@ + +#include "projet.h" + + +void init_dictionnaire(struct dictionnaire* D){ + D->tetes = NULL ; + D->nbelem = 0 ; +} + +void cons_dictionnaire(struct dictionnaire* D, char* fichier){ + char word[100] ; + FILE * f = fopen(fichier, "r"); + if(f == NULL) + exit(1) ; + + while(fscanf(f, "%s", word) != EOF){ + ajout_mot(D,word) ; + } + +} + + +void ajout_mot(struct dictionnaire* ptrD, char* MOT){ + int tailleMot = strlen(MOT) ; + struct noeud* tmp = ptrD->tetes ; + int i = 0, j = 0, position = 0; + bool sortie = false; + if(tmp != NULL){ + while(position < ptrD->nbelem && tmp[position].valeur != MOT[0]){ + position++ ; + } + if(position < ptrD->nbelem){ + tmp = &(tmp[position]) ; + while(!sortie){ + if(tmp->valeur == MOT[i]){ + i++ ; + if(i < tailleMot){ + j = 0 ; + struct noeud* liste = tmp->liste_noeud ; + while(j< tmp->nbfils && liste[j].valeur != MOT[i]) + j++ ; + if(j < tmp->nbfils){ + tmp = &(liste[j]) ; + } + else + sortie = true ; + } + else{ + tmp->complet = true ; + sortie = true ; + } + } + else + sortie = true ; + } + } + } + for(j = i ; j < tailleMot ; j++){ + if(j == 0 && position >= ptrD->nbelem){ + ptrD->nbelem +=1 ; + ptrD->tetes = realloc(ptrD->tetes , ptrD->nbelem*sizeof(struct noeud)) ; + ptrD->tetes [ptrD->nbelem-1].valeur = MOT[j] ; + ptrD->tetes [ptrD->nbelem-1].nbfils = 0 ; + ptrD->tetes [ptrD->nbelem-1].liste_noeud = NULL ; + if(j == tailleMot-1) + ptrD->tetes[ptrD->nbelem-1].complet= true ; + else + ptrD->tetes[ptrD->nbelem-1].complet = false ; + tmp = &ptrD->tetes[ptrD->nbelem-1]; + } + else{ + tmp->nbfils++ ; + tmp->liste_noeud = realloc(tmp->liste_noeud, (tmp->nbfils)*sizeof(struct noeud)) ; + tmp->liste_noeud[tmp->nbfils-1].valeur = MOT[j] ; + tmp->liste_noeud[tmp->nbfils-1].nbfils = 0 ; + tmp->liste_noeud[tmp->nbfils-1].liste_noeud = NULL ; + if(j == tailleMot-1) + tmp->liste_noeud[tmp->nbfils-1].complet = true; + else + tmp->liste_noeud[tmp->nbfils-1].complet = false ; + tmp = &tmp->liste_noeud[tmp->nbfils-1] ; + } + } + + +} + +bool appartient_mot(struct dictionnaire *D, char * MOT){ + if(D->tetes==NULL) return false ; + int length = strlen(MOT) ; + int i,j; + + bool exit = false , found = false ; + struct noeud N ; + + i = 0; + while(i < D->nbelem && D->tetes[i].valeur != MOT[0] ) + i++ ; + if(i==D->nbelem) return false ; + if(length == 1 && D->tetes[i].complet ) + found = true; + N = D->tetes[i] ; + i = 1 ; + + while(!exit && !found){ + j = 0 ; + while(j < N.nbfils && N.liste_noeud[j].valeur != MOT[i]){ + j++ ; + } + if(j < N.nbfils){ + i++ ; + if(i>=length && N.liste_noeud[j].complet){ + found = true ; + } + else{ + if(i>=length) + exit = true ; + else + N = N.liste_noeud[j] ; + } + } + else{ + exit = true ; + } + + + } + + return found ; +} +void correction(struct dictionnaire *D, char *phrase){ + FILE *f = fopen(phrase, "r"); + if(f!=NULL){ + int nbError = 0; + char mot[25]; + while(fscanf(f,"%s",mot)!=EOF){ + if(!appartient_mot(D,mot)){ + printf("il y a une erreur\n"); + printf("------------------------------------------------------------------\n"); + printf("%s\n",mot); + printf("------------------------------------------------------------------\n"); + nbError++; + } + + } + printf("La phrase contenait : %d erreurs\n", nbError); + } + +} + + + + + -- libgit2 0.21.2