Commit 762b7dc23eab55b8cec8ba6e814715d861bb024f
1 parent
70bf4fa9
dernier commit
Showing
7 changed files
with
51 additions
and
6 deletions
Show diff stats
@@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
1 | +CC=gcc | ||
2 | +CFLAGS=-W -Wall -ansi -pedantic | ||
3 | +LDFLAGS= | ||
4 | +EXEC=projet | ||
5 | + | ||
6 | +all: projet | ||
7 | + | ||
8 | +projet: fonctions.o main.o | ||
9 | + $(CC) -o projet fonctions.o projet.o $(LDFLAGS) | ||
10 | + | ||
11 | +fonctions.o: fonctions.c | ||
12 | + $(CC) -o fonctions.o -c fonctions.c $(CFLAGS) | ||
13 | + | ||
14 | +main.o: main.c fonctions.h | ||
15 | + $(CC) -o main.o -c main.c $(CFLAGS) | ||
16 | + | ||
17 | +clean: | ||
18 | + rm -rf *.o | ||
19 | + | ||
20 | +mrproper: clean | ||
21 | + rm -rf $(EXEC) | ||
0 | \ No newline at end of file | 22 | \ No newline at end of file |
No preview for this file type
No preview for this file type
projet.c
@@ -3,35 +3,39 @@ | @@ -3,35 +3,39 @@ | ||
3 | #include <string.h> | 3 | #include <string.h> |
4 | #include <stdbool.h> | 4 | #include <stdbool.h> |
5 | #include <ctype.h> | 5 | #include <ctype.h> |
6 | + | ||
6 | typedef struct noeud { | 7 | typedef struct noeud { |
7 | int valeur; | 8 | int valeur; |
8 | struct noeud *lettre[28]; | 9 | struct noeud *lettre[28]; |
9 | } noeud ; | 10 | } noeud ; |
11 | + | ||
10 | typedef struct{ | 12 | typedef struct{ |
11 | noeud *dictionnaire[26]; | 13 | noeud *dictionnaire[26]; |
12 | } dico; | 14 | } dico; |
15 | + | ||
13 | void creer_et_initialiser_le_noeud(noeud ** parbre, int v){ | 16 | void creer_et_initialiser_le_noeud(noeud ** parbre, int v){ |
14 | -*parbre=(noeud*)malloc(sizeof(noeud)); | ||
15 | -(*parbre)->valeur=v; | ||
16 | -int i; | ||
17 | -for(i=0;i<28;i++) | 17 | + *parbre=malloc(sizeof(noeud)); |
18 | + (*parbre)->valeur=v; | ||
19 | + for(int i=0;i<28;i++) | ||
18 | (*parbre)->lettre[i]=NULL; | 20 | (*parbre)->lettre[i]=NULL; |
19 | } | 21 | } |
22 | + | ||
20 | void remplissage(noeud ** parbre, char ch[128]){ | 23 | void remplissage(noeud ** parbre, char ch[128]){ |
21 | int i,n=strlen(ch); | 24 | int i,n=strlen(ch); |
22 | - if(& (*parbre)->valeur==NULL) | 25 | + if(*parbre==NULL) |
23 | creer_et_initialiser_le_noeud(parbre,tolower(ch[0])); | 26 | creer_et_initialiser_le_noeud(parbre,tolower(ch[0])); |
24 | for(i=1;i<n;i++){ | 27 | for(i=1;i<n;i++){ |
25 | if(ch[i]==39) | 28 | if(ch[i]==39) |
26 | parbre=&(*parbre)->lettre[26]; | 29 | parbre=&(*parbre)->lettre[26]; |
27 | else | 30 | else |
28 | parbre=&(*parbre)->lettre[tolower(ch[i])-'a']; | 31 | parbre=&(*parbre)->lettre[tolower(ch[i])-'a']; |
29 | - if(&(*parbre)->valeur==NULL) | 32 | + if(*parbre == NULL) |
30 | creer_et_initialiser_le_noeud(parbre,tolower(ch[i])); | 33 | creer_et_initialiser_le_noeud(parbre,tolower(ch[i])); |
31 | } | 34 | } |
32 | creer_et_initialiser_le_noeud(&(*parbre)->lettre[27],0); | 35 | creer_et_initialiser_le_noeud(&(*parbre)->lettre[27],0); |
33 | } | 36 | } |
34 | 37 | ||
38 | + | ||
35 | void lecture(noeud ** parbre, FILE *fichier,int v){ | 39 | void lecture(noeud ** parbre, FILE *fichier,int v){ |
36 | char ch[128]; | 40 | char ch[128]; |
37 | noeud ** tmp_parbre=parbre; | 41 | noeud ** tmp_parbre=parbre; |
@@ -39,6 +43,7 @@ void lecture(noeud ** parbre, FILE *fichier,int v){ | @@ -39,6 +43,7 @@ void lecture(noeud ** parbre, FILE *fichier,int v){ | ||
39 | if(tolower(ch[0])==v) | 43 | if(tolower(ch[0])==v) |
40 | remplissage(tmp_parbre,ch); | 44 | remplissage(tmp_parbre,ch); |
41 | } | 45 | } |
46 | + | ||
42 | void insertion_dictionnaire(noeud * Arbre[26]){ | 47 | void insertion_dictionnaire(noeud * Arbre[26]){ |
43 | int i; | 48 | int i; |
44 | for(i=0;i<26;i++){ | 49 | for(i=0;i<26;i++){ |
@@ -47,11 +52,13 @@ void insertion_dictionnaire(noeud * Arbre[26]){ | @@ -47,11 +52,13 @@ void insertion_dictionnaire(noeud * Arbre[26]){ | ||
47 | fclose(dico); | 52 | fclose(dico); |
48 | } | 53 | } |
49 | } | 54 | } |
55 | + | ||
50 | void initialiser_dictionnaire(noeud * Arbre[26]){ | 56 | void initialiser_dictionnaire(noeud * Arbre[26]){ |
51 | int i; | 57 | int i; |
52 | for(i=0;i<26;i++) | 58 | for(i=0;i<26;i++) |
53 | Arbre[i]=NULL; | 59 | Arbre[i]=NULL; |
54 | } | 60 | } |
61 | + | ||
55 | bool existe(noeud ** parbre,char ch[128]){ | 62 | bool existe(noeud ** parbre,char ch[128]){ |
56 | int n=strlen(ch); | 63 | int n=strlen(ch); |
57 | int i,cpt=0; | 64 | int i,cpt=0; |
@@ -74,6 +81,7 @@ bool existe(noeud ** parbre,char ch[128]){ | @@ -74,6 +81,7 @@ bool existe(noeud ** parbre,char ch[128]){ | ||
74 | } | 81 | } |
75 | else return false; | 82 | else return false; |
76 | } | 83 | } |
84 | + | ||
77 | void corriger_texte(noeud*arbre[26]){ | 85 | void corriger_texte(noeud*arbre[26]){ |
78 | char ch[128]; | 86 | char ch[128]; |
79 | FILE *texte=fopen("texte.txt","r"); | 87 | FILE *texte=fopen("texte.txt","r"); |
@@ -83,6 +91,7 @@ void corriger_texte(noeud*arbre[26]){ | @@ -83,6 +91,7 @@ void corriger_texte(noeud*arbre[26]){ | ||
83 | } | 91 | } |
84 | fclose(texte); | 92 | fclose(texte); |
85 | } | 93 | } |
94 | + | ||
86 | int main (){ | 95 | int main (){ |
87 | dico d; | 96 | dico d; |
88 | initialiser_dictionnaire(d.dictionnaire); | 97 | initialiser_dictionnaire(d.dictionnaire); |
@@ -93,6 +102,7 @@ int main (){ | @@ -93,6 +102,7 @@ int main (){ | ||
93 | printf("\nvoici les fautes dans le texte: \n \n"); | 102 | printf("\nvoici les fautes dans le texte: \n \n"); |
94 | corriger_texte(d.dictionnaire); | 103 | corriger_texte(d.dictionnaire); |
95 | printf("\n"); | 104 | printf("\n"); |
105 | + | ||
96 | return 0; | 106 | return 0; |
97 | } | 107 | } |
98 | 108 |
No preview for this file type
No preview for this file type