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);
} |
Partager