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