🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Quick question on file I/O...

Started by
1 comment, last by Grellin 22 years, 9 months ago
I am trying to learn how to use the C++ file I/O. To be more specific I have 2 story lines and based on the users response I want to display the proper "level" of the story. Is set up on good and evil and each have 25 levels. I have been able to pull up a specific number of lines to display and could probably set up a small routine to loop the read when needed. I was just wondering if I am going about this the best way. I read somewhere you could read one character at a time and did that but couldnt figure out how to make it stop at a specific point. It just read the whole file. I know this is probably a basic concept to many of you but my hair is rapidly turning grey, at least the small patch that is left. Any help would be appreciated. /* GRELLIN */
Steven Bradley .:Personal Journal:. .:WEBPLATES:. .:CGP Beginners Group:. "Time is our most precious resource yet it is the resource we most often waste." ~ Dr. R.M. Powell
Advertisement
A bunch of ideas, to go with a bunch of questions.

If you''re trying to deliver context-sensitive responses from a text file, a) you''d probably want to read in a couple of paragraphs into separate buffers (e.g. if you present the user with 3 choices, have the responses to each choice read in); b) you''d probably want to insert a ''marker'' character into your text file when you create it so the software knows where a paragraph/response ends (otherwise you''ll have to tell it exactly where to end).

Write a small tool that lets you either enter a paragraph of text or specify a text file. It takes the contents of the paragraph/file and appends it to the responses "resource" file, and inserts the marker character at the end of each new paragraph. (This could later from a basis for a complete dialog editor). Now, when you read data in from the response file (character-by-character, or however you please), read only until you encounter the marker. At that point, advance the file position and end your read.

Good markers are the unprintable ASCII characters - nothing that could be interpreted by a printf() statement.
there''s a file I/o tut on nexe that i wrote http://nexe.gamedev.net

also I''m writing a file logging class right now

Eric Wright o0Programmer0o

AcidRain Productions
Eric Wright o0Programmer0o

This topic is closed to new replies.

Advertisement