I apologize for the brevity. this is what I use to retrieve a file that was saved from a linked list.
it loads more than one linked list.
// Load the dat file to memory. This is a linked list.
int LoadList (DATAPTR headptr, int setuplines, char *Logfile,
char *start1limits, char *end1limits, char datasetup [][256])
{
// Open the file for input to memory.
FILE *file;
if ( (file = fopen(Logfile, "r"

) != NULL )
{
//Reset the ptr variable to the first entry.
wrkptr = headptr;
DATAPTR nextptr;
// Temp storage for text line recieved.
char *buff = new char[256];
// Skip over the first 10 lines.
for (int x = 0; x <= setuplines; x++)
{
fgets (buff, 256, file);
strcpy (datasetup [x], buff);
}
//*********************************
// This is the first check of the integrity of the dat file.
// Set end of the string to be compared.
buff [17] = NULL;
// If the these strings compare the initial data is correct.
if (strcmp (buff, "** START DATABASE"

)
{
return 3;
}
//*********************************
int done = false;
// Load the file to a linked list in memory.
// Until the end of the file is reached.
// If the previous check for the start database line
// fails, this while loop does not process because the
// done variable is set to true in the previous lines.
// The next seven lines are processed as if these lines
// were without error. The error check comes after when
// the start notes line is checked for its proper position.
while (!done)
{
// For removing the newline character.
int strln;
//*************************************
//load each Group field.
for(x = 0; x <= 7; x++)
{
//Read the next line from the disk.
fgets (buff, 256, file);
//Remove the newline character from the end of the string.
strln = strlen (buff);
buff [strln - 1] = NULL;
switch (x)
{
case 0:
strcpy (wrkptr->field1, buff);
break;
case 1:
strcpy (wrkptr->field2, buff);
break;
case 2:
strcpy (wrkptr->field3, buff);
break;
case 3:
strcpy (wrkptr->field4, buff);
break;
case 4:
strcpy (wrkptr->field5, buff);
break;
case 5:
strcpy (wrkptr->field6, buff);
break;
case 6:
strcpy (wrkptr->field7, buff);
break;
case 7:
strcpy (wrkptr->field8, buff);
break;
default:
break;
}//End of switch.
}//End of for. Loading the group fields for the entry is done.
//*************************************
//Read the next line from the disk.
fgets (buff, 256, file);
//Remove the newline character from the end of the string.
strln = strlen (buff);
buff [strln - 1] = NULL;
//*************************************
// Load notes1.
// If the next line is the start header line read the notes.
if (!strcmp (buff, start1limits))
{
// This is the working textptr.
TXTPTR tptr;
// Initalize the first line of the notes.
wrkptr->firstline1 = AddTextLine ();
tptr = wrkptr->firstline1;
//*****************************
// This is the counter for the number of lines
// read by the notes.
int y = 0;
//This is the limiting number of lines to be read.
int z = 1000;
//*****************************
int x = 0;
while (!x)
{
if (y < z)
y++;
else
{
// There are to many lines in the notes.
// This error can occur when the notes limits
// are not terminated properly at the end of
// the last entry.
return 2;
}
fgets (buff, 256, file);
//Remove the newline character from the end of the string.
strln = strlen (buff);
buff [strln - 1] = NULL;
//If this string is txtlimits this is the end of the notes.
if (!strcmp (buff, end1limits))
x = 1;
//Get the notes.
else
{
//******************************************
//The first line of the notes is placed in the first line ptr.
strcpy (tptr->textline, buff);
tsavedptr = AddTextLine ();
tptr->nextptr = tsavedptr;
tptr = tsavedptr;
//******************************************
}
}// end of while (!x).
}// end of if (!strcmp (buff, start1limits)).
//*************************************
// If we do not break here, the function adds an empty
// structure and fills all the fields with the field4
// of the last structure.
if (feof (file))
{
//done = true;
//continue;
return 0;
}
//*************************************
//*************************************
// Inialize the nextptr and link it to the previous ptr.
nextptr = AddNode ();
wrkptr->nextptr = nextptr;
wrkptr = nextptr;
//*************************************
}//End of while (!done), load fields and notes.
delete nextptr;
delete buff;
fclose(file);
}// end of if file open.
else
return 1; // file acess error.
return 0;
/* Return values
0 - file load OK
1 - unable to open file
2 - notes exceeds limit
3 - the start of the data is not in the correct spot
4
5
*/
}
email me and I will send yu the full code that resolves some of the pointers that are rather vague as listed here.