-
Saving a Variable???
Is it possible to save all data in a varaible to the Hard Drive to be loaded next time the program is run? For example, saving a multi-dimensional array to the C:\ drive and loading it when the program is run. I am not looking for outputting it to text I don't think.
Now I'll tell you WHY I want to do this, incase that isn't possible so that you guys can show me a better way.
Im making a simple program with the potential for a lot of input. Im using a 4 dimensional array (for the input of questions and answers for several different areas or study) and I want the input to be there still when the program is closed and opened.
Please help me with a way to accomplish this. Thanks a lot!!!
-
You need to export your data into a file on your harddrive. Look into File I/O. Open a new text file, put whatever info you need into it (encrypt it if you want), then you load from that file. Keep in mind, your parser has to know how the file is formatted, that way everything gets loaded into the correct place.
-
How would I go about that?
I know how to save data to a file...
Code:
fp = fopen("C:/Blah.txt", "w");
fprintf(fp......
...and so on
But I would have no idea how to save so much into a file...
Say the user entered 500 characters into subject 1 area 1 of an array, 5000 characters into subject 2 area 12, and so on...how would i load everything where its supposed to be?
There could be hundreds of inputs stored in this array...
-
This topic is called serialization. A good buzzword to start you off. So, is this big hunk of data you have something of a:
Code:
struct x { char a[100][100][100][100]; };
Or a;
Code:
struct x { char **** a; }
If the former, you may just fwrite the sizeof it. In the latter, you may need to implement some sort of file format to re-build the data in the file to memory.