I have this file
3
10 10 10
0 0 0
0 0 1
1 0 0
1 1 1
1 0
0 0
1 1

and I want to read the first line as intger in X
the 2nd line in camp1
the 3rd line in camp2
line 4 to 6 into vertices
the other lines into edges

I wrote this code but it doesn't work ,, it doesn't fill the strcture at all.

typedef struct {
        point3d camP1;
        point3d camP2;
        double X;
        int noEdge;
        int noVer;
        point3d* vertices;
        edge*  edges;
    } scene;

int readFile(char *filname, scene *sc) {

    FILE* fp;
    fp = fopen("objCoordinate.txt", "r");
    if (fp == NULL) {
        printf(" Error!!!\n");
    }

    else
    {
        char lines [Line_Max];

        while (fgets (lines, Line_Max, fp) != NULL) {
             fscanf (fp, "%d", sc->focLen);  //Scan first line into variable

             fscanf (fp, "%f" "%f" "%f" , sc->camP1.x , sc->camP1.y , sc->camP1.z);

             fscanf (fp, "%f" "%f" "%f" , sc->camP2.x , sc->camP2.y , sc->camP2.z);

             for (int i=0 ; i < noVer ; i++)
                     fscanf (fp, "%f" "%f" "%f" , sc->vertices->x , sc->vertices->y , sc->vertices->z);

            for (int j=0; j< noEdge; j++)
                fscanf (fp, "%f" "%f"  , sc->edges->start , sc->edges->end );

        }
    }


    fclose(fp);

    return 0;
}

Can someone help me with it, please?

what is point3d?

line 31 doesn't work because there is no memory allocated for the pointers. We hve no clue what point3d and edge are so we can't really help you very much, except to say they are pointers which need to be allocated before attempting to read the data into them.

point3d is a struct that has three intger values x,y, and z.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.