Blame view

projet.c 2.48 KB
0c252f1e   Raouak Haroun   commit du 2 avril
1
2
3
4
  #include <stdio.h>

  #include <stdlib.h>

  #include <string.h>

  #include <stdbool.h>

70bf4fa9   Raouak Haroun   commit du 23 avril
5
  #include <ctype.h>

762b7dc2   Raouak Haroun   dernier commit
6
  

70bf4fa9   Raouak Haroun   commit du 23 avril
7
  typedef struct noeud {

0c252f1e   Raouak Haroun   commit du 2 avril
8
    int valeur;

70bf4fa9   Raouak Haroun   commit du 23 avril
9
    struct noeud *lettre[28];

0c252f1e   Raouak Haroun   commit du 2 avril
10
  } noeud ;

762b7dc2   Raouak Haroun   dernier commit
11
  

70bf4fa9   Raouak Haroun   commit du 23 avril
12
13
14
  typedef struct{

  	noeud *dictionnaire[26];

  } dico;

762b7dc2   Raouak Haroun   dernier commit
15
  

d01b83b4   Raouak Haroun   commit du 4 avril
16
  void creer_et_initialiser_le_noeud(noeud ** parbre, int v){

762b7dc2   Raouak Haroun   dernier commit
17
18
19
    *parbre=malloc(sizeof(noeud));

    (*parbre)->valeur=v;

    for(int i=0;i<28;i++)

70bf4fa9   Raouak Haroun   commit du 23 avril
20
      (*parbre)->lettre[i]=NULL;

0c252f1e   Raouak Haroun   commit du 2 avril
21
  }

762b7dc2   Raouak Haroun   dernier commit
22
  

d01b83b4   Raouak Haroun   commit du 4 avril
23
  void remplissage(noeud ** parbre, char ch[128]){

70bf4fa9   Raouak Haroun   commit du 23 avril
24
  	int i,n=strlen(ch);

762b7dc2   Raouak Haroun   dernier commit
25
  	if(*parbre==NULL)

70bf4fa9   Raouak Haroun   commit du 23 avril
26
  		creer_et_initialiser_le_noeud(parbre,tolower(ch[0]));

d01b83b4   Raouak Haroun   commit du 4 avril
27
  	for(i=1;i<n;i++){

70bf4fa9   Raouak Haroun   commit du 23 avril
28
29
30
31
  		if(ch[i]==39)

  			parbre=&(*parbre)->lettre[26];

  		else

  			parbre=&(*parbre)->lettre[tolower(ch[i])-'a'];

762b7dc2   Raouak Haroun   dernier commit
32
  		if(*parbre == NULL)

70bf4fa9   Raouak Haroun   commit du 23 avril
33
  			creer_et_initialiser_le_noeud(parbre,tolower(ch[i]));

0c252f1e   Raouak Haroun   commit du 2 avril
34
  	}

70bf4fa9   Raouak Haroun   commit du 23 avril
35
  	creer_et_initialiser_le_noeud(&(*parbre)->lettre[27],0);

0c252f1e   Raouak Haroun   commit du 2 avril
36
37
  }

  

762b7dc2   Raouak Haroun   dernier commit
38
  

70bf4fa9   Raouak Haroun   commit du 23 avril
39
  void lecture(noeud ** parbre, FILE *fichier,int v){

d01b83b4   Raouak Haroun   commit du 4 avril
40
  	char ch[128];

d01b83b4   Raouak Haroun   commit du 4 avril
41
42
  	noeud ** tmp_parbre=parbre;

  	while(fscanf(fichier,"%s",ch)==1)

70bf4fa9   Raouak Haroun   commit du 23 avril
43
44
  		if(tolower(ch[0])==v)

  			remplissage(tmp_parbre,ch);

0c252f1e   Raouak Haroun   commit du 2 avril
45
  }

762b7dc2   Raouak Haroun   dernier commit
46
  

70bf4fa9   Raouak Haroun   commit du 23 avril
47
48
49
50
51
52
53
54
  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);

  	}

  }

762b7dc2   Raouak Haroun   dernier commit
55
  

70bf4fa9   Raouak Haroun   commit du 23 avril
56
57
58
59
60
  void initialiser_dictionnaire(noeud * Arbre[26]){

  	int i;

  	for(i=0;i<26;i++)

  		Arbre[i]=NULL;

  }

762b7dc2   Raouak Haroun   dernier commit
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
  	int a,cpt=0;

70bf4fa9   Raouak Haroun   commit du 23 avril
65
  	noeud ** tmp_parbre=parbre;

dd84636f   Raouak Haroun   dernier commit
66
  	for(int i=0;i<n-1;i++){

70bf4fa9   Raouak Haroun   commit du 23 avril
67
68
69
70
71
72
73
74
75
76
77
78
79
  		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'];

  			}

  		}

  	}

  	if ((*tmp_parbre)!=NULL){

  		if (tolower(ch[cpt])==(*tmp_parbre)->valeur)

  			if ((*tmp_parbre)->lettre[27]!=NULL)

dd84636f   Raouak Haroun   dernier commit
80
  				a=1;

70bf4fa9   Raouak Haroun   commit du 23 avril
81
  	}

dd84636f   Raouak Haroun   dernier commit
82
83
  	else a=0;

  	return a;

70bf4fa9   Raouak Haroun   commit du 23 avril
84
  }

70bf4fa9   Raouak Haroun   commit du 23 avril
85
86
  void corriger_texte(noeud*arbre[26]){

  	char ch[128];

d01b83b4   Raouak Haroun   commit du 4 avril
87
  	FILE *texte=fopen("texte.txt","r");

70bf4fa9   Raouak Haroun   commit du 23 avril
88
89
90
91
  	while(fscanf(texte,"%s",ch)==1){

  		if(!existe(&arbre[tolower(ch[0])-'a'],ch))

  			printf("%s\n",ch);

  	}

d01b83b4   Raouak Haroun   commit du 4 avril
92
  	fclose(texte);

70bf4fa9   Raouak Haroun   commit du 23 avril
93
  }

762b7dc2   Raouak Haroun   dernier commit
94
  

70bf4fa9   Raouak Haroun   commit du 23 avril
95
96
97
98
99
100
101
102
103
  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);

d01b83b4   Raouak Haroun   commit du 4 avril
104
  	printf("\n");

762b7dc2   Raouak Haroun   dernier commit
105
  

0c252f1e   Raouak Haroun   commit du 2 avril
106
  	return 0;

0c252f1e   Raouak Haroun   commit du 2 avril
107
  }

70bf4fa9   Raouak Haroun   commit du 23 avril
108