Blame view

projet.c 2.18 KB
e67ab31b   hraouak   update
1
  #include "projet.h"

762b7dc2   Raouak Haroun   dernier commit
2
  

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

762b7dc2   Raouak Haroun   dernier commit
4
5
6
    *parbre=malloc(sizeof(noeud));

    (*parbre)->valeur=v;

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

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

0c252f1e   Raouak Haroun   commit du 2 avril
8
  }

762b7dc2   Raouak Haroun   dernier commit
9
  

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

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

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

18d7b5f9   Raouak Haroun   dernier commit
13
  	  creer_et_initialiser_le_noeud(parbre,tolower(ch[0]));

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

18d7b5f9   Raouak Haroun   dernier commit
15
16
17
18
19
20
  	  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]));

0c252f1e   Raouak Haroun   commit du 2 avril
21
  	}

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

0c252f1e   Raouak Haroun   commit du 2 avril
23
24
  }

  

762b7dc2   Raouak Haroun   dernier commit
25
  

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

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

d01b83b4   Raouak Haroun   commit du 4 avril
28
29
  	noeud ** tmp_parbre=parbre;

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

18d7b5f9   Raouak Haroun   dernier commit
30
31
  	  if(tolower(ch[0])==v)

  	    remplissage(tmp_parbre,ch);

0c252f1e   Raouak Haroun   commit du 2 avril
32
  }

762b7dc2   Raouak Haroun   dernier commit
33
  

70bf4fa9   Raouak Haroun   commit du 23 avril
34
  void insertion_dictionnaire(noeud * Arbre[26]){

18d7b5f9   Raouak Haroun   dernier commit
35
36
37
38
39
40
    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
41
  }

762b7dc2   Raouak Haroun   dernier commit
42
  

70bf4fa9   Raouak Haroun   commit du 23 avril
43
  void initialiser_dictionnaire(noeud * Arbre[26]){

18d7b5f9   Raouak Haroun   dernier commit
44
45
46
    int i;

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

      Arbre[i]=NULL;

70bf4fa9   Raouak Haroun   commit du 23 avril
47
  }

762b7dc2   Raouak Haroun   dernier commit
48
  

2eee91cd   Raouak Haroun   dernier commit
49
  int existe(noeud ** parbre,char ch[128]){

18d7b5f9   Raouak Haroun   dernier commit
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
    int n=strlen(ch);

    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'];

        }

      }

    }

    if ((*tmp_parbre)!=NULL){

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

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

  	a=1;

    }

    else a=0;

dd84636f   Raouak Haroun   dernier commit
70
  	return a;

70bf4fa9   Raouak Haroun   commit du 23 avril
71
  }

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

18d7b5f9   Raouak Haroun   dernier commit
73
74
75
76
77
    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);

70bf4fa9   Raouak Haroun   commit du 23 avril
78
  	}

18d7b5f9   Raouak Haroun   dernier commit
79
    fclose(texte);

70bf4fa9   Raouak Haroun   commit du 23 avril
80
  }

762b7dc2   Raouak Haroun   dernier commit
81
  

2eee91cd   Raouak Haroun   dernier commit
82
83
84
  

  void desallouer_arbre(noeud *arbre){

    

18d7b5f9   Raouak Haroun   dernier commit
85
86
87
88
89
90
91
92
    if(arbre != NULL)

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

        if(arbre->lettre[i] != NULL)

  	desallouer_arbre(arbre->lettre[i]);

      }

    else

      free(arbre);

    

2eee91cd   Raouak Haroun   dernier commit
93
94
95
96
97
  }

  void desallouer_dictionnaire(noeud*arbre[26]){

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

      desallouer_arbre(arbre[i]);

  }

18d7b5f9   Raouak Haroun   dernier commit
98