diff --git a/tree.c b/tree.c index 1cd7faf..722c6ae 100644 --- a/tree.c +++ b/tree.c @@ -1,27 +1,35 @@ -#include -#include #include +#include +#include #include -#define size 128 -int alphabet[27] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',39 }; +typedef struct noeud * Noeud; +struct noeud { char valeur ; Noeud fils[26]; Noeud complet;}; +struct dico { struct noeud * tableau[26];}; -struct noeud { char valeur; struct noeud * fils[27]; int complet;}; -struct dico {struct noeud* tableau[26];}; int i; -typedef struct noeud* Noeud; -Noeud cons_noeud (char a) -{ - Noeud pN = malloc(sizeof(struct noeud)); - (*pN).valeur=a; - (*pN).complet=0; - for(int i=0; i<28; i++) - { - (*pN).fils[i]=NULL; - } - return pN; +void cons_noeud (Noeud * pN, char a) +{ int i; + *pN =malloc( sizeof(struct noeud)); + (*pN)->valeur=a; + (*pN)->complet=NULL; + for(i=0; i<26; i++) + (*pN)->fils[i]=NULL; +} + +void ajout_mot_noeud (Noeud * pN, char *mot) +{ + int i; + int n=strlen(mot); + if(*pN == NULL) cons_noeud(pN, tolower(mot[0])); + for(i=1; ifils[tolower(mot[i])-97]; + if(&(*pN)->valeur==NULL) + cons_noeud(pN, tolower(mot[i])); + }cons_noeud(&(*pN)->complet,49); } + void ajout_noeud_dico(struct dico * D, Noeud N) { @@ -31,137 +39,62 @@ void ajout_noeud_dico(struct dico * D, Noeud N) D->tableau[i]=N; } -//tolower --> fonction qui prend une lettre quelconque en argument et renvoie son équivalent en miniscule -/*void ajout_mot_noeud(Noeud * pN, char mot[size]) -{ - int j=0; - int n=strlen(mot); - if(*pN==NULL) + +void cons_dico_file(char * nomfichier, struct dico* D) +{ + int i; + char * mot; + FILE * fp; + fp=fopen(nomfichier, "r"); + if(fp==NULL) + return; + while((fscanf(fp,"%s",mot)==1)) { - *pN=cons_noeud(tolower(mot[0])); - *pN=(*pN)->fils[j]; + ajout_mot_noeud(&(D->tableau[mot[i]-97]),mot); + i++; + } - *pN=(*pN)->fils[j]; - printf("%d\n",j); - for(int i=1; ivaleur)!= tolower(mot[i])) - {j++;} - if(j==0) - { - *pN= (*pN)->fils[j+1]; - } - else if (*pN == NULL) - { - *pN =cons_noeud(tolower(mot[i])); - *pN= (*pN)->fils[j]; - } - } - (*pN)->complet=1; -}*/ +} -void ajout_mot_noeud(Noeud * pN, char mot[size]) +int appartient_dico(struct dico D,char * mot) { - int i,n=strlen(mot); - if(& (*pN)->valeur==NULL) - *pN = cons_noeud(tolower(mot[0])); - for(i=1;ialphabet[tolower(mot[i])-'a']; - if(&(*pN)->valeur==NULL) - *pN= cons_noeud(tolower(mot[i])); - } - (*pN)->complet=1; + } -//Reprendre cette fonction! ; -/*void cons_dico_file(FILE* fp, struct dico* D) -{ char mot[size]; - if(fp==NULL) - return; - while(fscanf(fp,"%s",a)==1)*pN=NULL; - { ajout_mot(D,a); - //D->dernier++;} //int i=O; - - }*/ - - -/*int rech_mot(struct dico D,char mot [size]) -{ char * mot; - mot=sup_lettre("emilie");N)->fils[j]!=NULL || (*pN)->fils[j]->valeur!= mot[i+1]) //int i=O; - {j++;} - printf("%s\n",mot); - Noeud N; //int i=O; - int nbre; - for(int i=0;inoeud; - else //int i=O; - nbre=0; - } - if(N.complet==1)return newmot //int i=O; - nbre=1;N)->fils[j]!=NULL || (*pN)->fils[j]->valeur!= mot[i+1]) //int i=O; - {j++;} - } - else char * mot; - mot=sup_lettre("emilie"); //int i=O; - printf("%s\n",mot); - nbre= 0; - } - return nbre; //int i=O; - }*/ - - -/*void correction_texte(char filename[size], struct dico D) +void correction_texte(char* nomfichier, struct dico D) { - FILE *fp=fopen(filename, "r"); - char mot[size]; //int i=O; - int x; char * mot; -} - mot=sup_lettre("emilie"); - printf("%s\n",mot); - if(fp==NULL)return newmot + FILE *fp; + fp=fopen(nomfichier, "r+"); + char * mot; + if(fp==NULL) return; - else //int i=O; - { - for(int i=1; ifils[j]!=NULL || (*pN)->fils[j]->valeur!= mot[i+1]) - {j++;} //int i=O; - mot=sup_lettre("emilie"); - printf("%s\n",mot);eur!\n"); - printf("%s",mot); - } - } - } - - - }*/ + while((fscanf(fp,"%s",mot)==1)) + { + if(appartient_dico(D,mot)==1) + return; + else + printf("%s\n"mot); + } +} int main() { - Noeud pN; - pN =cons_noeud('a'); - ajout_mot_noeud(&pN,"arbre"); - printf("%c\n", pN->valeur); + return 0; } + + + + + + + + + + + + -- libgit2 0.21.2