Bonjour a tous,
j'ai fais un programme et j'ai toujours une erreur de segmentation et je sais pas comment la corrigé. c'est la fonction construction_binaire qui pose problème. je pense ça vient de la variable colonne. mais je sais pas comment le corriger.
enfaite ma fonction "codage" met des "0" dans la colonne "colonne" jusqu'à "k" et a partir de "k+1" il met des "1".
j'utilise cette fonction dans la fonction 'construction_binaire' . elle consiste a remplir le tableau a 2 dimension. mais comme j'ai écrit j'ai toujours des erreurs de segmentation. et je vois pas du tout comment le corriger. si qq1 pourrais m'aidé a debugé ou ou moins me donné une idée. je vous remercie d'avance.
je vous join le code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
 
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include<sys/stat.h>
 
#define L 10
#define C 10
 
 
int cpt=0;
int colonne = 1;
 
 
int indice_coupure(int tableau[], int g, int d)
{
 
  int  SommeG = 0;
  int SommeD = 0;
  int indice;
 
  while (g <= d)
    {
 
      if (SommeG < SommeD)
	{
	  SommeG += tableau[g];
	  g++;          
	}      
      else
	{
	  SommeD += tableau[d];
	  d--;      
	}     
    }       
 
  indice=g-1;
 
  return indice ;
 
 
}
 
 
 
 
 
 
void codage(char tab[L][C],int tab_freq[],int debut,int fin,int colonne){
 
  int k,i,j;
 
 
  k=indice_coupure(tab_freq, debut,fin);
 
 
 
  for(i=debut;i<=k;i++){
    tab[i][colonne]='0';
  }
 
  for(j=k+1;j<=fin;j++){
    tab[j][colonne]='1';
  }
  /*
    for (i=0;i<10;i++){
    for(j=0;j<10;j++){
    printf("%c",tab[i][j]);
    }
    printf ("\n");
    }
  */
 
 
 
 
}
 
void initialisation(char tab[L][C]){
 
  int i,j ;
 
  for(i=0;i<C;i++){
 
    for(j=0;j<L;j++){
      tab[i][j]=' ';
    }
 
  }
 
 
 
}
 
 
void construction_binaire(char tab[L][C], int tab_freq[],int debut,int fin,int col){
 
 
  int k,i,j;
  int debut_g,debut_d;
  int fin_g,fin_d;
 
 
 
  k=indice_coupure(tab_freq, debut,fin);
 
  debut_g=debut;
  fin_g=k;
 
  debut_d=k+1;
  fin_g=fin;
 
 
 
  if (colonne = 1){ 
    codage( tab, tab_freq, debut, fin,colonne );
 
  }
  else {
    codage( tab, tab_freq, debut_g, fin_g,colonne );
    codage( tab, tab_freq, debut_g, fin_g,colonne );
 
  }
 
  while((fin - debut )>= 1){
    construction_binaire( tab,  tab_freq, debut_g, fin_g,col+1);
    construction_binaire( tab, tab_freq,debut_d, fin_d,col+1);
  } 
 
 
 
}
 
 
 
 
int main (int argc, char ** argv){
  int tab_frequence[10]={1,2,3,4,5,6,7,8,9,10};
  char tab[L][C];
  int i,j;
  initialisation(tab);
  /* for(i=0;i<10;i++){
     
  for(j=0;j<10;j++){
  printf("%c", tab[i][j]=' ');
  }
  printf("\n");
  }
  printf("\n");*/
 
  //codage(tab, tab_frequence,0,9,2);
  //codage(tab, tab_frequence,5,9,3);
 
  construction_binaire( tab, tab_frequence,0,9,colonne);
 
 
  return (EXIT_SUCCESS);
 
}