Hi guys, I've got a question that hopefully someone can answer.
I have a file that contains the following structure:
g hub
f 100 200 300 12
f 356 403 345 484
f 333 212 1203 393
g door glass
f 323 9292 383
f 32 3838 3939
f 1231 333 22
f 323 112 3939
f 323 3939 2281 2002 3883
[etc etc, there are 32 of these blocks]
Each block follows the same format, where 1 line starts with g followed by some string (all on one line) and then a bunch of lines that start with f followed by an unfixed number of integers.
My problem is I want to store the integers on these lines into a C integer array, so that I can pass it into an OpenGL function I am using.
My initial thought is for each block of data indicated by the string starting with g, I would count the number of lines for each object in the file, declare an array of that size, and then simply read in the numbers into the array.
Pretend each line that starts with f only had 3 numbers per line, I could go:
int array[NUM_LINES_OF_OBJECT][3];
char str[1024];
int i;
for(i = 0; i < NUM_LINES_OF_OBJECT; i++) {
fscanf(myFile,"%s %f %f %f",str,&array[i][0],&array[i][1],&array[i][2]);
}
However there is an unknown number of integers that are on each line that begin with f. How can I make an array that has all the data for each line stored in it without knowing explicitly how many %f's to use in fscanf?
Ideally, I want to make 32 arrays for each of these "objects" from my text file.
int object1[Num_Object_Lines][ ?? ] <== unknown number of elements per line.
Does anyone have any idea how to do this? I would very much appreciate it if you could help me out.
Thanks.
Attached is the text file I am using. You might have to open it in an editor other than notepad otherwise the formatting will be screwed up.