graemephillips
Programmer
Could someone tell me how to open a program, scan through whole lines in C, check for certain parameters and then assign values to variables in C? For instance, I have to use the C program to open a program named cube.tri, whose format is shown below: -
8 6
1 1 1
1 1 -1
1 -1 1
1 -1 -1
-1 1 1
-1 1 -1
-1 -1 1
-1 -1 -1
4 0 1 3 2
4 4 6 7 5
4 0 2 6 4
4 1 5 7 3
4 0 4 5 1
4 2 3 7 6
The section of code is a description of a cube. The first line gives the number of vertices followed by the number of faces on the shape. Next is a list of the vertices, according to the number stated in the first line, each with 3 co-ordinates. Once all the vertices have been stated, there are the face descriptions. The first number in the line states how many vertices are used to make up the corners of the faces. The following numbers refer to the vertices, whose co-ordinates will be used in the construction of the face, which are stated in chronological order in the vertices part of the file; for instance, 1 would be the (1, 1, 1) vertex and 2 the (1, 1, -1) vertex etc.
8 6
1 1 1
1 1 -1
1 -1 1
1 -1 -1
-1 1 1
-1 1 -1
-1 -1 1
-1 -1 -1
4 0 1 3 2
4 4 6 7 5
4 0 2 6 4
4 1 5 7 3
4 0 4 5 1
4 2 3 7 6
The section of code is a description of a cube. The first line gives the number of vertices followed by the number of faces on the shape. Next is a list of the vertices, according to the number stated in the first line, each with 3 co-ordinates. Once all the vertices have been stated, there are the face descriptions. The first number in the line states how many vertices are used to make up the corners of the faces. The following numbers refer to the vertices, whose co-ordinates will be used in the construction of the face, which are stated in chronological order in the vertices part of the file; for instance, 1 would be the (1, 1, 1) vertex and 2 the (1, 1, -1) vertex etc.