Bonjour à tous,
J'ai un autre seg fault quelque part mais j'avoue que je ne trouve pas d'où provient-il.
Voilà la source (qui compile :p):
main.c
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
#include "fonctions.h"
 
int main(int argc, char **argv)
{
  NOEUD             Table[MAX_CHAR];
  unsigned char     Set_Bit [8] = {128, 64, 32, 16, 8, 4, 2, 1};
  short    int      x;
  const char        sr[]="cob.txt";
  const char        de[]="boc.txt";
  unsigned char     k;
  NOEUD             root = NULL;
  NOEUD             elem = NULL;
  long int          frequence;
  FILE              *src = NULL,
                    *des = NULL;
  element           *tete = NULL,
                    *elm = NULL;
  int a;
 
    usage ();
       if ((src=fopen(sr, "r")) == NULL){
          printf ("%s not found!\n", sr);
           return H_ERROR;
           }
        else
         if ((des=fopen(de, "w")) == NULL){
            printf ("can't create %s\n", de);
             return H_ERROR;
            }
 
     if ((x = Alloc_Table (Table)) < 0){
        printf("Error when mallocing the table...\n");
         return H_ERROR;
        }
 
 
     frequence = Constrcut_Table (src, Table);
     printf("tri de la table ...");
     Sort_Table      (Table);
     printf("Done               [fréquence %d]\n", frequence);
 
      for (a=0; a<MAX_CHAR; a++)
        if (Table[a]->car)
          printf("%c <> %d\n", Table[a]->car, Table[a]->occur);
 
        printf("construction de la liste chaînée...");
        Create_List (Table, &tete);   // c'est içi que ca foire apparament car quand j'affiche   // par la suite pour vérifier que la liste est ok j'ai le seg fault donc...
        printf("Done\n");
       printf("List is okay?!\n");
        //for (elm=tete; elm->lnext!=NULL; elm=elm->lnext)
         elm = tete;
         printf("%c -> %d\n", elm->nd->car, elm->nd->occur);
       printf("she's!\n");
 
        printf("construction de l'arbre...");
        Construct_Tree (tete, &root);
        printf ("Done");
 
       Free_List (tete);
 
    printf("OK\n");
    //printf("size of table: %d", sizeof(Table));
     Free_Table (Table);
     fclose (src);
     src = NULL;
     fclose (des);
     des = NULL;
 
	return H_DONE;
}
fonctions.h
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
#ifndef H_FONCTIONS
#define H_FONCTIONS
 
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
 
#define H_DONE         0
#define H_ERROR       -1
#define MAX_CHAR     255
 
typedef struct NOEUD{
   char   car;
   int           occur;
   struct NOEUD *R, *L;
    }*NOEUD;
 
typedef struct element{
   NOEUD nd;
   struct element *lnext;
    }element;
 
void usage              (void);
int  Alloc_Table        (NOEUD tab[MAX_CHAR]);
void Sort_Table         (NOEUD tab[MAX_CHAR]);
int  Constrcut_Table    (FILE* src, NOEUD tab[MAX_CHAR]);
void Check_Char         (char c, NOEUD tab[MAX_CHAR]);
void Init_Noeud         (NOEUD n, unsigned char car);
void Free_Table         (NOEUD tab[MAX_CHAR]);
void Set_All_To_Zero    (NOEUD tab[MAX_CHAR]);
void Create_Noeud       (NOEUD noeud, int freq, const unsigned char c,
                         NOEUD fl, NOEUD fr);
void Create_List        (NOEUD tab[MAX_CHAR], element **t);
void Construct_Tree     (element* t, NOEUD *rt);
 
#endif
fonctions.c
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
165
#include "fonctions.h"
 
void usage (void){
  printf("                  Huffman\n\n");
  printf("usage: compress <option> <source> <destination>\n");
  printf("option:  -c    -----------------------    compress\n");
  printf("         -d    -----------------------    decompress\n");
    }
 
void Sort_Table (NOEUD tab[MAX_CHAR]){
   int  count1,
        count2;
   NOEUD tmp;
 
     for (count1 = 0; count1 < MAX_CHAR; count1++)
       for (count2 = 0; count2 < (MAX_CHAR-1); count2++)
         if (tab[count2]->occur > tab[(count2+1)]->occur){
            tmp = tab[count2];
            tab[count2] = tab[(count2+1)];
            tab[(count2+1)] = tmp;
             }
    }
 
void Check_Char (char c, NOEUD tab[MAX_CHAR]){
   int count;
 
     for (count=0; count<MAX_CHAR; count++){
       if (tab[count]->car == 0){
         tab[count]->car = c;
         tab[count]->occur = 1;
          break;
         }
        else
          if (tab[count]->car == c){
             tab[count]->occur++;
              break;
             }
       }
    }
 
void Set_All_To_Zero (NOEUD tab[MAX_CHAR]){
   int count;
 
    for (count=0; count<MAX_CHAR; count++){
       tab[count]->car =    0;
       tab[count]->R   = NULL;
       tab[count]->L   = NULL;
        }
    }
 
int Constrcut_Table (FILE* src, NOEUD tab[MAX_CHAR]){
    int count1;
    char c;
    long int freq = 0;
 
     printf("Construction de la table ...");
     freq = 0;
     Set_All_To_Zero (tab);
 
      while ((c=fgetc(src)) != EOF){
         Check_Char (c, tab);
         freq++;
          }
      printf("Done\n");
      return freq;
    }
 
int Alloc_Table(NOEUD *tab){
   int count;
 
    for (count=0; count<MAX_CHAR; count++){
      tab[count] = malloc (sizeof(struct NOEUD));
       if (tab == NULL) return H_ERROR;
     }
      return H_DONE;
    }
 
void Free_Table         (NOEUD tab[MAX_CHAR]){
   int count;
 
     for (count=0; count<MAX_CHAR; count++)
      free (tab[count]);
    }
 
void Create_Noeud (NOEUD n, int freq, const unsigned char c,
                         NOEUD fl, NOEUD fr){
 
    n = malloc (sizeof (struct NOEUD));
    n->occur = freq;
    n->R = fr;
    n->L = fl;
    }
 
void Create_List (NOEUD tab[MAX_CHAR], element **t){
   int count=0;
   element *tmp = NULL;
   element *em = NULL;
 
     while ((tab[count]->car)&&(count < MAX_CHAR)){
        em = malloc (sizeof(struct element));
        em->lnext = NULL;
        em->nd = tab[count];
 
         if (*t == NULL){
            *t   = em;
            tmp =  em;
           }
          else{
             tmp->lnext = em;
             tmp        = em;
              }
           count++;
         }
    }
 
void Free_List (element* t){
   element *em,
           *sv;
 
    em = t;
 
   while (em){
     sv = em;
     em = em->lnext;
     free (sv);
    }
    }
 
void Construct_Tree (element* t, NOEUD *rt){
    element *elm = NULL,
            *lst = NULL,
            *ttmp = NULL,
            *all  = NULL,
            *ptr = NULL;
    NOEUD    nd = NULL;
 
    elm = t;
 
     while (elm->lnext){
        while (elm->lnext){
           lst = elm;
           elm = elm->lnext;
           Create_Noeud (nd, lst->nd->occur+elm->nd->occur, '!',
                        lst->nd, elm->nd);
 
           all = malloc (sizeof (struct element));
           all->nd = nd;
           all->lnext = NULL;
 
            if (ptr == NULL)  ptr = all;
             else{
              ptr->lnext = all;
              ptr = all;
              }
            if (ttmp == NULL) ttmp = all;
            //free (lst);
            //free (elm);
             elm = elm->lnext;
            }
           elm = ttmp;
           ptr = NULL;
           ttmp = NULL;
         }
       *rt = ttmp->nd;
    }
Merci d'avance les gars! de mon côté je continue à chercher au cas où