Hi,
I have coded a very simple save function for a little game I'm messing about with at the moment. The program just writes all the variables to a text file.
Say I have a "hitpoints" variable, written as:
This will be written to a text file when the save function is called, and will be written like so:Code:int hp = 25;
This will be written as follows when in saved, text format:Code:fprintf(file, "hp = %d;", hp);
Note: 25 may not be the actual value of the variable when it is saved.Code:hp = 25;
The reason I have written it to the text file this way is because I was hoping I would be able to "load" this straight back into the program and actually execute this line, thus reinitialising the value to what it was when the save function was called.
My problem is I don't know how to actually execute the lines inside the text file when the program is running.
Reading this text file back into the program is no problem at all, but I don't want it just printed out to the screen.
Can anyone help me out?
Thanks.