I'm working on an engine for running various simple text-based adventures based on nodes with a limited range of options for the player to select from. (a working beta with a partially complete example module is attached)
Currently, I'm trying to clean up the code so that I can rewrite the event and link parsers into something more effective, but ran into some problems with a function supposed to load the contents of a text file into an array of strings.
What works:
- The number of lines is correctly counted and stored in the counter the external function uses
- The array is created and the lines are loaded from the file into it
- The array contains the correct contents in the filetostrarray() function
What DOESN'T work:
- load_paragraph() doesn't have access to the strings in the array and crashes the program when trying to display them
In
void load_paragraph():
Code:
string parfile=par_file(current_node);
int lines;
string *line;
filetostrarray(parfile, &lines, line);
In filetostrarray
Code:
void filetostrarray(string file, int* lines, string *readlines) {
*lines=lines_in_file(file);
if (*lines) { fstream line_in(file.c_str(), ios::in);
readlines=new string[*lines];
for (int i=0; i<*lines; i++) getline(line_in, readlines[i]);
line_in.close();
line_in.clear(); } }