Commit caf6b693b0912af3cdace8cebdeff1ac67343414

Authored by vsalingu
1 parent 83f9e1cf

debut lecture de words et ajout dans le dico

Showing 1 changed file with 45 additions and 8 deletions   Show diff stats
1 -#include<stdio.h> 1 +#include <stdio.h>
2 #include <stdlib.h> 2 #include <stdlib.h>
3 3
  4 +
  5 +typedef struct cell* ptarbre;
4 typedef struct cell* ptcellule; 6 typedef struct cell* ptcellule;
5 -typedef struct cell* ptarbre  
6 -typedef struct cell {int lettre; ptarbre arbre; ptcellule suivant;};  
7 7
  8 +typedef struct cell {
  9 + int lettre;
  10 + ptarbre arbre;
  11 + ptcellule suivant;
  12 +} cell;
  13 +
  14 +/* Pas utile
8 void init_dico() 15 void init_dico()
9 { 16 {
10 ptarbre arbre; 17 ptarbre arbre;
11 arbre=NULL; 18 arbre=NULL;
12 } 19 }
13 - 20 +*/
  21 +ptarbre rech(ptarbre arbre, int lettre)
  22 +{
  23 + while((arbre!=NULL) && (arbre->lettre != lettre))
  24 + arbre=arbre->suivant;
  25 + return arbre;
  26 +}
14 void ajout_dico(ptarbre arbre, int lettre) 27 void ajout_dico(ptarbre arbre, int lettre)
15 { 28 {
16 arbre=malloc(sizeof(cell)); 29 arbre=malloc(sizeof(cell));
@@ -19,16 +32,40 @@ void ajout_dico(ptarbre arbre, int lettre) @@ -19,16 +32,40 @@ void ajout_dico(ptarbre arbre, int lettre)
19 arbre->suivant=NULL; 32 arbre->suivant=NULL;
20 } 33 }
21 34
  35 +void affiche_dico(ptarbre arbre)
  36 +{
  37 +
  38 + printf("%c\n", arbre->lettre);
  39 +}
22 40
23 41
24 int main() 42 int main()
25 { 43 {
26 - init_dico();  
27 - 44 + ptarbre arbre;
  45 + arbre=NULL;
  46 + char c;
28 // Ouvrir fichier 47 // Ouvrir fichier
29 - 48 + FILE *fp = fopen("words","r");
  49 + if (fp==NULL)
  50 + printf("words inaccessible ",fp);
  51 + else
  52 + printf("words accessible n",fp);
  53 +
  54 + while (fscanf(fp,"%d",&c)!= EOF) // lecture de tout le fichier
  55 + {
  56 + while (c!='\n')
  57 + {
  58 + if (rech(arbre,c)==NULL)
  59 + {
  60 + ajout_dico(arbre,c);
  61 + }
  62 + arbre=arbre->arbre; // On va à l'étage d'après pour former le mot dans l'arbre
  63 + affiche_dico(arbre);
  64 + }
  65 + }
  66 +
  67 +
30 68
31 - while c!= EOF // lecture de tout le fichier  
32 69
33 70
34 return 0; 71 return 0;