From 38be3329e5bb64c851e9160e01034e1b71333fea Mon Sep 17 00:00:00 2001 From: rsSimonin Date: Fri, 5 Apr 2019 11:57:25 +0200 Subject: [PATCH] makefile et main --- arbre.c | 77 ++++++++++++++++++++++++++++++++++++++++++----------------------------------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/arbre.c b/arbre.c index 824cbc2..d0eaf96 100644 --- a/arbre.c +++ b/arbre.c @@ -1,23 +1,20 @@ -#include -#include -#include -#include +#include "arbre.h" -#define TAILLE 27 -typedef struct arbre{ - char val; - struct arbre *suite[TAILLE]; - bool finmot; //1 si fin de mot -}Arbre; +// typedef struct arbre{ +// char val; +// struct arbre *suite[TAILLE]; +// bool finmot; //1 si fin de mot +// }Arbre; +// +// typedef struct dico { +// Arbre *alpha[TAILLE]; +// }Dico; -typedef struct dico { - Arbre *alpha[TAILLE]; -}Dico; - -int calculcase(char c){ +int calculcase(char c) +{ if(c==39){ return 26; } @@ -39,13 +36,15 @@ bool fin_de_mot(struct arbre *arbre) return arbre->finmot; } -void ini_dico(struct dico * pt_dico){ +void ini_dico(struct dico *pt_dico) +{ printf("ini_dico\n"); for(int i=0;ialpha[i]=NULL; } } -void creation_arbre(Arbre **ppt_arbre,char c){ +void creation_arbre(Arbre **ppt_arbre,char c) +{ printf("creation arbre\n"); Arbre *monarbre=malloc(sizeof(struct arbre)); monarbre->val=c; @@ -57,7 +56,8 @@ void creation_arbre(Arbre **ppt_arbre,char c){ } -void ajout_mot(struct arbre **arbrecourant,char *mot,int i){ +void ajout_mot(struct arbre **arbrecourant,char *mot,int i) +{ printf("%s:length:%zu \n",mot,strlen(mot)); @@ -67,6 +67,9 @@ void ajout_mot(struct arbre **arbrecourant,char *mot,int i){ creation_arbre(arbrecourant,mot[i]); } i++; + if(mot[i]!='\0'){ + (*arbrecourant)->finmot=true; + } ajout_mot(&((*arbrecourant)->suite[calculcase(mot[i])]),mot,i); } @@ -84,7 +87,8 @@ void charger_arbre(FILE *fp, struct dico **ppt_dico) } -void free_arbre(struct arbre *pt_arbre){ +void free_arbre(struct arbre *pt_arbre) +{ if (pt_arbre==NULL){ return ; } @@ -94,7 +98,8 @@ void free_arbre(struct arbre *pt_arbre){ free(pt_arbre); } -void free_dico(struct dico *pt_dico){ +void free_dico(struct dico *pt_dico) +{ if (pt_dico==NULL){ return ; } @@ -106,7 +111,8 @@ void free_dico(struct dico *pt_dico){ free(pt_dico); } -void affiche_arbre(struct arbre *arbre){ +void affiche_arbre(struct arbre *arbre) +{ if(arbre==NULL){ return ; } @@ -116,7 +122,8 @@ void affiche_arbre(struct arbre *arbre){ } } -void affiche_dico(struct dico *dico){ +void affiche_dico(struct dico *dico) +{ if(dico==NULL){ return ; } @@ -130,16 +137,16 @@ void affiche_dico(struct dico *dico){ } -int main (){ - FILE* fp = fopen("words-no-accents","r"); //amelioration entrée - if(fp == NULL){ return EXIT_FAILURE;} //File is not readable - - struct dico *mondico=malloc(sizeof(struct dico)); - charger_arbre(fp,&mondico); - affiche_dico(mondico); - - - free_dico(mondico); - fclose(fp); - return 0; -} +// int main (){ +// FILE* fp = fopen("words-no-accents","r"); //amelioration entrée +// if(fp == NULL){ return EXIT_FAILURE;} //File is not readable +// +// struct dico *mondico=malloc(sizeof(struct dico)); +// charger_arbre(fp,&mondico); +// affiche_dico(mondico); +// +// +// free_dico(mondico); +// fclose(fp); +// return 0; +// } -- libgit2 0.21.2