Advertisement

Lesson 10 Question

Started by March 25, 2003 12:29 AM
1 comment, last by dnagcat 21 years, 11 months ago
In lesson 10 each line of the text file is read by this function

void readstr(FILE *f, char* string)
{
     do
     {
     fgets(string, 255, f);
     }while((string[0]=='/') || (string)[0]=="\n"));
     return;
}
 
then when you do the setup for the world you call this function in a loop (controlled by the number of triangles you want to load) and you call the above function at the beginning of each loop. OK...so how do you read consective strings in the world.txt file with this function. I understand it reads the string from the file and stores it in string ( a pointer to a buffer to store data read )...but every time you call this function wouldn't you just read the first line of the file... how does it know to read the next line the next time it gets called? I hope that made sense! [edited by - dnagcat on March 25, 2003 1:30:25 AM]
I believe the fgets(...) function reads the file for a string, and then moves the get pointer to the following character. So for example if you call fgets(string, 255, f)... it reads up to 255 characters until it finds either a newline or a eof (end of file) and then copies that to your buffer (string). Then it moves the get pointer (the starting position for your file input) to the character after the newline. So basicly every time you call fgets it reads line by line down the page. Hope that helps...
I'm don't know much but I can try to help... just email me at... Shadow_0f_Light@Yahoo.com(the '0' in 'Of' is a zero :P)
Advertisement
Makes perfect sense...thanks

This topic is closed to new replies.

Advertisement