From caf6b693b0912af3cdace8cebdeff1ac67343414 Mon Sep 17 00:00:00 2001 From: vsalingu Date: Thu, 28 Mar 2019 12:16:18 +0100 Subject: [PATCH] debut lecture de words et ajout dans le dico --- projet.c | 53 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/projet.c b/projet.c index 78f348d..f170227 100644 --- a/projet.c +++ b/projet.c @@ -1,16 +1,29 @@ -#include +#include #include + +typedef struct cell* ptarbre; typedef struct cell* ptcellule; -typedef struct cell* ptarbre -typedef struct cell {int lettre; ptarbre arbre; ptcellule suivant;}; +typedef struct cell { + int lettre; + ptarbre arbre; + ptcellule suivant; +} cell; + +/* Pas utile void init_dico() { ptarbre arbre; arbre=NULL; } - +*/ +ptarbre rech(ptarbre arbre, int lettre) +{ + while((arbre!=NULL) && (arbre->lettre != lettre)) + arbre=arbre->suivant; + return arbre; +} void ajout_dico(ptarbre arbre, int lettre) { arbre=malloc(sizeof(cell)); @@ -19,16 +32,40 @@ void ajout_dico(ptarbre arbre, int lettre) arbre->suivant=NULL; } +void affiche_dico(ptarbre arbre) +{ + + printf("%c\n", arbre->lettre); +} int main() { - init_dico(); - + ptarbre arbre; + arbre=NULL; + char c; // Ouvrir fichier - + FILE *fp = fopen("words","r"); + if (fp==NULL) + printf("words inaccessible ",fp); + else + printf("words accessible n",fp); + + while (fscanf(fp,"%d",&c)!= EOF) // lecture de tout le fichier + { + while (c!='\n') + { + if (rech(arbre,c)==NULL) + { + ajout_dico(arbre,c); + } + arbre=arbre->arbre; // On va à l'étage d'après pour former le mot dans l'arbre + affiche_dico(arbre); + } + } + + - while c!= EOF // lecture de tout le fichier return 0; -- libgit2 0.21.2