'Trouble using fscanf with a dynamic array

Soy try to make a code that take a .txt in imput and create dynamically a list of particle (with the structure particle created in a header file). The problem here is that when I try to printf the values of the list after it's values are implemented with the scanf function, the only thing gcc return is a list of int 0. Do you know what is wrong with my code? Thank you by advance and sorry for my bad english(I'm French)

int main(int argc, char **argv) {
FILE *p_file = NULL;
p_file = fopen(argv[1], "r");

if (p_file == NULL) {
    fprintf(stderr, "Cannot read file %s!\n", argv[1]);
    exit(EXIT_FAILURE);
}
int particle_number;

int fscanf_result = fscanf(p_file, "%d\n", &particle_number);

printf("nombre de particules : %d\n", particle_number);

double px;
double py;
double vx;
double vy;
double mass;
double radius;
double color;

int line_nbr = 0;

particle *list_of_particle;

list_of_particle = (particle*)malloc(particle_number * sizeof(particle));

fscanf_result = fscanf(p_file, "%lf,%lf,%lf,%lf,%lf,%lf,%lf\n", &px, &py, &vx, &vy, &mass, &radius, &color);

 while (fscanf_result != EOF) {
    if (fscanf_result != 7) {
        printf("Line number %d is not syntactically correct in particles-tests!\n",
                 line_nbr);
        exit(EXIT_FAILURE);
    }

    particle *p = malloc(sizeof(particle));

    (p -> position).x = px;
    (p -> position).y = py;
    (p -> velocity).x = vx;
    (p -> velocity).y = vy;
    p -> mass = mass;
    p -> radius = radius;
    p -> color = color;

    printf("couleur du pointeur : %d\n", (p -> color));

    list_of_particle[line_nbr] = *p;
    line_nbr ++;


    printf("vérification de la couleur de la liste : %d\n", (list_of_particle[line_nbr]).color);

    printf("valeur du fscanf : %d\n", fscanf_result);

    //printf("vérification du rayon de la particule numéro %d : %lf\n", line_nbr, (list_of_particle[line_nbr] -> radius));

    fscanf_result = fscanf(p_file, "%lf,%lf,%lf,%lf,%lf,%lf,%lf\n", &px, &py, &vx, &vy, &mass, &radius, &color);

    free(p);

 }
 fclose(p_file);

p_file = NULL;

}



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source