salut tout le monde,
mon but c'est de séparer les champs d'une ligne et les stocker dans une pile, ces champs dans la ligne (sous forme de chaine de caractères) sont séparés par des ","
par exemple la ligne est:
125895,A,8807,USER,TRD,1,TLX,
pour cela j'ai fait cette fonction:

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
static pile* Sep_Line (char * line_in)
{
 
printf("Beginning of Sep_Line() for the line: %s \n", line_in);
 
   char* line_aux = malloc(sizeof(char) * MAX_LINE_LEN);
   printf("allocation for the line \n");
   char *field 	;
   field = malloc(sizeof(char) * MAX_FIELD_NAME_LEN);
 
   printf("allocation for pile \n");
   pile *ligne = malloc(sizeof(pile));
   printf("the allocation of pile is done \n");
 
   if (ligne == NULL)
   {
    printf("allocation failed \n ");
   }
 
   int i=0;
   int l;
   size_t len;
 
   strcpy(line_aux, line_in);
   printf("the line on which we are separating fields is : %s \n",line_aux); 
   strcat(line_aux, ",");
   printf("the line is now : %s \n", line_aux);
   strcat(line_aux,"\0");
   l= strlen(line_aux);
 
/* Storing the line's content in a "pile" */
 
do
{
    len = strcspn(line_aux, ","); /* len contain the lenght of the initial segment of line_aux which doed not contain "," */
    printf("the length of the fields is :%d \n",len);
    strncpy (field, line_aux, len); /* field will contain the 1st field in the 1st iteration the second one in the second iteration ainsi de suite */
    strcat (field,"\0"); 
    printf("the field's value is : %s \n", field);
 
    Push(&ligne, field); /* In the first iteartion, the "pile" will contain the first field */
    printf("we stored the field's value in the pile \n");
    line_aux = line_aux + len + 2; /* To make line_aux points to the next field: line_aux will point to the caracter just following the "," */
 
} 
 
while (line_aux == "\0");
 
printf("End of Sep_Line() \n \n");
 
return (ligne);
 
}
la structure pile que j'utilise est:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
typedef struct pile {
   char* content;
   struct pile * prev;
  } pile;
et la fonction Push est:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
void Push(pile **p, char *Val)
 
{
        pile *element= malloc(sizeof(pile));
        if (element == NULL)  /* If the allocation is failed. */
                {
                exit(EXIT_FAILURE);
                }
        element->content = Val;
        element->prev = *p;
        *p = element;       /* The pointer points to the last element */
}
lorsque j'exècute la fonction Sep_Line , il s'arrête au message:
the field's value is : BRDG_TAG
et il m'affiche : Segmentation Fault
je comprends pas où est la Segmentation Fault!!??
SVP quelqu'un pourrait m'aider !! c'est urgent
et merci