Hi all, I'm currently working on a project about linked list. I need to create 3 linked list based on the information inside a file. I already started but really doubt my method is the easiest and best way. If anyone could help me as to how should I made it, it would really help me !
As I said, I need to use the information of a file. Each information is written on a separate line, and we don't know the number of line in the file. Now here's how is separated the information in the file: On the first line, there's the name of a model with his polygon ID number. On x lines following the model's line are the polygon's points. Each points contains his 3 coordinates (x,y,z) on the same line. Here are some line of the file:
1.24 -1.52 3.78
2.23 1.25 2.47
4.44 2.58 0.97
5.32 1.52 8.12
0.23 -1.25 -2.47
2.32 6.25 1.65
1.25 5.82 3.24
Now I just learned linked lists contents and still taking all the info I can find. Anyway, I thought I could use a function that would read the first line and add the model's name and polygon's ID in their respected lists. Then, it would call another function to read the following lines (until we reach another model) and also add them to their respected lists. Where I doubt is if it's going to be effective and how I'm going to read the lines and indentify them. Here's the declaration of my items.
typedef struct point* PtrPoint;
typedef struct point
float z; /* cooordinates of my point */
PtrPoint next; /* points on the next point */
typedef struct polygon* PtrPolygon;
typedef struct polygon
int numPolygon; /* ID number of the polygon */
int nbPoints; /* number of points of the polygon */
PtrPoint headPoint; /* head of the points' list */
PtrPolygon next; /* points on the next polygon */
typedef struct model* PtrModel;
typedef struct model
char nomModel[MAX_CAR_MODEL]; /* name of the model */
int nbPolygons; /* number of polygons */
PtrPolygon headPolygon; /* head of the polygon's list for the model */
PtrPolygon next; /* points the next model */
PtrModel headModele; /* head of the models' list */
Hope I gave enough informations to get some possible solutions as to how to get this done. I can post a diagram of the linked lists and my function if needed.
Thanks a lot for your time and patience.