dd84636f
Raouak Haroun
dernier commit
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>
typedef struct noeud {
int valeur;
struct noeud *lettre[28];
} noeud ;
typedef struct{
noeud *dictionnaire[26];
} dico;
void creer_et_initialiser_le_noeud(noeud ** parbre, int v){
*parbre=malloc(sizeof(noeud));
(*parbre)->valeur=v;
for(int i=0;i<28;i++)
(*parbre)->lettre[i]=NULL;
}
|
70bf4fa9
Raouak Haroun
commit du 23 avril
|
22
|
|
dd84636f
Raouak Haroun
dernier commit
|
23
24
25
26
27
28
29
30
31
32
33
|
void remplissage(noeud ** parbre, char ch[128]){
int i,n=strlen(ch);
if(*parbre==NULL)
creer_et_initialiser_le_noeud(parbre,tolower(ch[0]));
for(i=1;i<n;i++){
if(ch[i]==39)
parbre=&(*parbre)->lettre[26];
else
parbre=&(*parbre)->lettre[tolower(ch[i])-'a'];
if(*parbre == NULL)
creer_et_initialiser_le_noeud(parbre,tolower(ch[i]));
|
70bf4fa9
Raouak Haroun
commit du 23 avril
|
34
|
}
|
dd84636f
Raouak Haroun
dernier commit
|
35
|
creer_et_initialiser_le_noeud(&(*parbre)->lettre[27],0);
|
70bf4fa9
Raouak Haroun
commit du 23 avril
|
36
37
|
}
|
70bf4fa9
Raouak Haroun
commit du 23 avril
|
38
|
|
dd84636f
Raouak Haroun
dernier commit
|
39
40
41
42
43
44
45
|
void lecture(noeud ** parbre, FILE *fichier,int v){
char ch[128];
noeud ** tmp_parbre=parbre;
while(fscanf(fichier,"%s",ch)==1)
if(tolower(ch[0])==v)
remplissage(tmp_parbre,ch);
}
|
70bf4fa9
Raouak Haroun
commit du 23 avril
|
46
|
|
dd84636f
Raouak Haroun
dernier commit
|
47
48
49
50
51
52
|
void insertion_dictionnaire(noeud * Arbre[26]){
int i;
for(i=0;i<26;i++){
FILE *dico=fopen("dico.txt","r");
lecture(&Arbre[i],dico,i+'a');
fclose(dico);
|
70bf4fa9
Raouak Haroun
commit du 23 avril
|
53
|
}
|
70bf4fa9
Raouak Haroun
commit du 23 avril
|
54
55
|
}
|
dd84636f
Raouak Haroun
dernier commit
|
56
57
58
59
|
void initialiser_dictionnaire(noeud * Arbre[26]){
int i;
for(i=0;i<26;i++)
Arbre[i]=NULL;
|
70bf4fa9
Raouak Haroun
commit du 23 avril
|
60
61
|
}
|
dd84636f
Raouak Haroun
dernier commit
|
62
|
int existe(noeud ** parbre,char ch[128]){
|
70bf4fa9
Raouak Haroun
commit du 23 avril
|
63
|
int n=strlen(ch);
|
dd84636f
Raouak Haroun
dernier commit
|
64
65
66
67
68
69
70
71
72
73
74
75
|
int a,cpt=0;
noeud ** tmp_parbre=parbre;
for(int i=0;i<n-1;i++){
if((*tmp_parbre)!=NULL){
if(tolower(ch[i])==(*tmp_parbre)->valeur){
cpt++;
if (ch[i+1]==39)
tmp_parbre=&(*tmp_parbre)->lettre[26];
else
tmp_parbre=&(*tmp_parbre)->lettre[tolower(ch[i+1])-'a'];
}
}
|
70bf4fa9
Raouak Haroun
commit du 23 avril
|
76
|
}
|
dd84636f
Raouak Haroun
dernier commit
|
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
if ((*tmp_parbre)!=NULL){
if (tolower(ch[cpt])==(*tmp_parbre)->valeur)
if ((*tmp_parbre)->lettre[27]!=NULL)
a=1;
}
else a=0;
return a;
}
void corriger_texte(noeud*arbre[26]){
char ch[128];
FILE *texte=fopen("texte.txt","r");
while(fscanf(texte,"%s",ch)==1){
if(!existe(&arbre[tolower(ch[0])-'a'],ch))
printf("%s\n",ch);
}
fclose(texte);
}
|
70bf4fa9
Raouak Haroun
commit du 23 avril
|
94
|
|
dd84636f
Raouak Haroun
dernier commit
|
95
96
97
98
99
100
101
102
103
104
|
int main (){
dico d;
initialiser_dictionnaire(d.dictionnaire);
insertion_dictionnaire(d.dictionnaire);
printf("-----------------------------------------------------------\n");
printf("Bienvenue dans le correcteur orthographique de HAROUN V1.0\n");
printf("-----------------------------------------------------------\n");
printf("\nvoici les fautes dans le texte: \n \n");
corriger_texte(d.dictionnaire);
printf("\n");
|
70bf4fa9
Raouak Haroun
commit du 23 avril
|
105
106
|
return 0;
|
70bf4fa9
Raouak Haroun
commit du 23 avril
|
107
|
}
|
dd84636f
Raouak Haroun
dernier commit
|
|
|