Original Post
I have a program where I can enter some data and then save, I can also load the data back into the program if I wish. I am able to save the data then load it in the same session; however, after I leave the program after I save then start it up again and try to load the data it freazes up. here is the code for my functions that load and save my data
class dataio{
public:
void savefile(char * dest, const void * data, int amount);
void loadfile(char * source, void * data, int amount);
};dataio dataio;
void dataio::savefile(char * dest, const void * data, int amount)
{
FILE *SaveFile;
SaveFile = fopen(dest, "wb"); // opens file for writing and in binary mode
fwrite (&amount, sizeof(int), 1, SaveFile);
fwrite (data, sizeof(data), amount, SaveFile);
fclose (SaveFile);
}
void dataio::loadfile(char * source, void * data, int amount)
{
FILE *loadfile;
loadfile = fopen(source,"rb");
fread(&amount, sizeof(int), 1, loadfile);
fread (data, sizeof(data), amount, loadfile);
fclose(loadfile);
}
and here is the code where I save and load my data
if(keys[17] && keys['S'])//if control and 's' is pressed
{
dataio.savefile("spells.txt",spells,sizeof(spell)*10);//save data to "spells.txt"
}
if(keys[17] && keys['L'])//if control and 'l' is pressed
{
dataio.loadfile("spells.txt",spells,sizeof(spell)*10);//load data from "spells.txt"
}
'spell' is a class holding my variables and 'spells' is an array of the class 'spell' I don't think i'm inputting the last parameter in right, but i don't know of any other way. any and all tips are appreciated