I'm trying to set up a double linked-list, that is a linked-list within a linked-list. the structure looks like this:
Code:
struct Dat
{
int acc;
int spd;
Dat *nextdat;
Dat *prevdat;
};
struct Node
{
char name [64];
char pass [16];
int avg_acc;
int avg_spd;
Dat *dat,
*dat_h,
*dat_t;
Node *next,
*prev;
};
Node *node, //current node
*list_h, //head
*list_t; //tail
my problem is saving the entire structure to a file, and then being able to open it up later. Saving the initial linked-list isn't a problem. But the pointers within the first linked-list which create the second linked-list may be a problem. Also, I can't come up with a successful way to get the data from the file and back into a linked list. My initial idea was to set up an initial node, open the file, save the data from the first node to the initial node, then create a new node, save the next data to that node, and so on until the eof is encountered. The problem is getting the second linked-list into the file, and back out. Here is my attempt at saving the file:
Code:
void LList::SaveToFile ()
{
int i;
ofstream data ("data.dat");
node = list_h;
while (node)
{
data.write((char*)node, sizeof(Node)); node = node->next; //does this write the internal linked-list as well?
}
data.close ();
}
Can anyone help me with the syntax for this file operation or point me somewhere that describes this type of problem?