Archived

This topic is now archived and is closed to further replies.

Lesson 10 Question

This topic is 5378 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites