Jump to content
  • Advertisement


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


Lesson 10 Question

This topic is 5660 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)
     fgets(string, 255, f);
     }while((string[0]=='/') || (string)[0]=="\n"));
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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!