Hi, all, me again (no, don't hide...[grin])
I'm having trouble geeting my program to run. It's (eventually) going to be an isometric game engine, but I seem to be having trouble with my .ini file loading function. I know it's this, because the code loads and displays a window fine, until I add my function call to the mix. The idea is that the function reads an .ini file, and stores the data in a struct. This data includes a path to my graphics, screen resolution, boolean variable for fullscreen/windowed modes, and a few other bits and bobs. The program compiles and links fine, but when I come to run it, I don't even get a chance to blink before it closes itself down.
As always, I'm using the Code::Blocks ver1.0 RC2 IDE with MinGW compiler.
Now for the code:
misc.h:
#ifndef MISC_
#define MISC_
#include <string>
#include <vector>
using namespace std;
typedef struct {
public:
string inistyle; //.ini style
string graphics_path; // path to game graphics
string tileset_list; // path to list of tilesets
bool fullscreen; // fullsceen value
long int xres;
long int yres;
} INI_FILESTYPE; // the effective "config" file struct
typedef struct {
public:
string inistyle; // .ini style
long int numsets; // number of tilesets
vector<string> tilesets; // names of each tileset
} INI_TOTALTILESTYPE; // the struct that holds the names of
// all the tilesets for loading
typedef struct {
public:
string inistyle; // .ini style
string basepath; // path from current to tileset
string eventpath; // path to event graphics
long int num_tiles; // number of tiles in set
vector<string> tilenames; // filenames of each tile
} INI_TILESTYPE; // the tileset struct for loading tiles
INI_FILESTYPE ReadConfig(char* filename);
//INI_TOTALTILESTYPE ReadTotTiles(string filename);
//INI_TILESTYPE ReadTileset(string filename);
#endif
main.cpp, ReadConfig() function
INI_FILESTYPE ReadConfig(char* filename)
{
ifstream infile(filename);
string style,arg,cmd;
INI_FILESTYPE files;
infile >> style;
if(style != "inistyle=")
{
MessageBox(NULL,"Error in .INI file. file should start with 'inistyle= '","Error!",MB_OK);
}
else
infile >> style;
if(style == "files")
{
files.inistyle = style;
bool found_gpath=false;
bool found_tilesets=false;
bool found_xres=false;
bool found_yres=false;
bool found_fullscreen=false;
bool done=false;
while(!done)
{
if(infile.eof()==true)
break;
else
{
infile >> cmd;
if(cmd == "graphics=" && found_gpath == false)
{
infile >> files.graphics_path;
found_gpath=true;
}
else if(cmd == "tilesetlist=" && found_tilesets == false)
{
infile >> files.tileset_list;
found_tilesets=true;
}
else if(cmd == "fullscreen=" && found_fullscreen == false)
{
infile >> files.fullscreen;
found_fullscreen=true;
}
else if(cmd == "xres=" && found_xres == false)
{
infile >> files.xres;
found_xres=true;
}
else if(cmd == "yres=" && found_yres == false)
{
infile >> files.yres;
found_yres=true;
}
}
}
}
}
I know it's something to do with this function, because I've taken out all uses of the returned struct, so it just runs the function, before setting up the window. Any Help would be appreciated.