Blame view

correcteur.c 980 Bytes
7197538b   mclaudel   Projet modifié
1
2
3
  #include <stdio.h>
  #include <stdlib.h>
  #include <stdbool.h>
5a0b8312   mclaudel   Algorithme amélio...
4
  #include <string.h>
7197538b   mclaudel   Projet modifié
5
  
5a0b8312   mclaudel   Algorithme amélio...
6
  #define MAX_LETTRES 30
7197538b   mclaudel   Projet modifié
7
8
9
  
  
  typedef struct node {
5a0b8312   mclaudel   Algorithme amélio...
10
    char l;
7197538b   mclaudel   Projet modifié
11
12
13
14
15
16
    struct node * lettres[27];
    bool fin_de_mot;
    int dernier;
  } Node;
  
  
5a0b8312   mclaudel   Algorithme amélio...
17
  void ajout(Node **N, char mot)
7197538b   mclaudel   Projet modifié
18
  {
5a0b8312   mclaudel   Algorithme amélio...
19
20
21
    Node *nouveau = malloc(sizeof(struct node));
    (*nouveau).l=mot;
    for (int i=0; i<27; i++) nouveau->lettres[i]=NULL;
7197538b   mclaudel   Projet modifié
22
23
24
25
    *N = nouveau;
  }
  
  
5a0b8312   mclaudel   Algorithme amélio...
26
  void ajout_alphab(Node ** pn, char *  mot,int cpt)
7197538b   mclaudel   Projet modifié
27
  {
5a0b8312   mclaudel   Algorithme amélio...
28
29
30
31
32
33
34
35
    int i = 0;
    while (mot[cpt] != '\0'){
      while ((*pn)->lettres[i] != NULL){
        if (strcmp(&(*pn)->l,mot) != 0){
  	i++;
        }
         *pn=(*pn)->lettres[i];
         return ajout_alphab(pn,mot,cpt++);
7197538b   mclaudel   Projet modifié
36
      }
5a0b8312   mclaudel   Algorithme amélio...
37
38
39
40
      ajout(&(*pn)->lettres[i],mot[cpt]);
      *pn=(*pn)->lettres[i];
      cpt++;
    }
7197538b   mclaudel   Projet modifié
41
42
43
  }
  
  
5a0b8312   mclaudel   Algorithme amélio...
44
45
  Node * charger_arbre(Node ** Arbre){
    FILE * dico;
7197538b   mclaudel   Projet modifié
46
    char mot[MAX_LETTRES];
5a0b8312   mclaudel   Algorithme amélio...
47
    dico = fopen("words.txt","r");
7197538b   mclaudel   Projet modifié
48
    while (fscanf(dico,"%s",mot) == 1){
5a0b8312   mclaudel   Algorithme amélio...
49
      ajout_alphab(Arbre,mot,0);
7197538b   mclaudel   Projet modifié
50
    }
5a0b8312   mclaudel   Algorithme amélio...
51
52
    fclose(dico);
    return *Arbre;
7197538b   mclaudel   Projet modifié
53
54
  }
  
5a0b8312   mclaudel   Algorithme amélio...
55
56
57
58
  
  int main(){
    return 0;
  }