Thread: Saving a Variable???

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    13

    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!!!

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    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.
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    13
    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...
    Last edited by almo89; 02-15-2006 at 04:31 PM.

  4. #4
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about printing a variable???
    By Hoser83 in forum C++ Programming
    Replies: 2
    Last Post: 03-31-2006, 01:57 PM
  2. How accurate is the following...
    By emeyer in forum C Programming
    Replies: 22
    Last Post: 12-07-2005, 12:07 PM
  3. static class variable vs. global variable
    By nadamson6 in forum C++ Programming
    Replies: 18
    Last Post: 09-30-2005, 03:31 PM
  4. Replies: 2
    Last Post: 04-12-2004, 01:37 AM
  5. write Variable and open Variable and get Information
    By cyberbjorn in forum C++ Programming
    Replies: 2
    Last Post: 04-09-2004, 01:30 AM