Skip to main content
gamedev.net
🔒 Locked

External File Reading

Started by n1zap 0 replies 300+ views
Original Post
n1zap
n1zap
I want my OGL program to read a file and tell it what to do from a easily editable file. I don't want to keep modifying code from the source. What I want to do is play a number of video files within a list. Like a .txt or something. A .txt that tells it where the file is located and when to play it etc... I want the ogl program to start up and then the code tells it to read the .txt (or whatever file) and then play the videos listed in the file. How can I achieve this?
Sam Gamgee
Sam Gamgee
Well reading a file is fairly easy. Take a look at MSDN for the following commands: fopen(), fscanf(), fprintf(), & fclose(). I'll just give a quick example of how to use them to read a text file:

FILE *f = NULL;char VideoFilePath[256];f = fopen("videos.txt", "r"); // open the file "videos.txt" for reading ("r")if(!f)  return;  // file doesn't exist or some other error...fscanf(f, "%s", &VideoFilePath);  // read the first string of text in the filefclose(f);  // don't forget to close everything...


That will read whatever is in the file up until it reaches a space or a new line and store that string in "VideoFilePath". Using these commands however, you can also read in integers, floats, the works.

-Walter

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.