here is the relevant code from my program, I am just gonna post it here now because I do not have access from home.
I'' try your suggestion, looks promising.
Code:
void Save(Users* &head)
{
Users *savelist;
savelist=head;
int i=0;
for(savelist=head;savelist;savelist=savelist=savelist->next)
{
//cout << savelist->Fname<<endl;
//cout << savelist->Sname<<endl;
i++;
// getch();
}
/*FILE *fp;
if ((fp =fopen("D:\\Profiles.dat","r+b")) == NULL)
{
fp =fopen("D:\\Profiles.dat","w+b");
// error
//tprintf("Creating File, retry to create user");
getch();
}
savelist=head;
while (savelist!=NULL)
{
cout <<"saving" <<endl;
fwrite(&savelist->Fname,sizeof(&savelist),1,fp);
savelist=savelist->next;
}
fclose(fp);*/
savelist=head;
ofstream outfile;
outfile.open("Profiles.dat",ios::out| ios::app |ios::binary);
//outfile <<head<<"\n";
//outfile<<"Begin" <<"\n";
do
{
outfile <<savelist->user.Fname <<"\n";
outfile <<savelist->user.Sname <<"\n";
outfile <<savelist->user.SepID <<"\n";
outfile <<savelist->user.UserID <<"\n";
savelist=savelist->next;
}
while(savelist!=NULL);
outfile << "END";
outfile.close();
cout << "Save succesful";
}
void Login(int i,Users* &head)
{
int profileID;
clrscr();
cout <<"Enter your student ID(if you have not created a profile with your user ID, you will need to return to the main menu)"<<endl;
cin>>profileID;
char ch ='\0';
int length;
char * buffer;
i=0;
Users *newrec;//=head;
int endloop=1;
ifstream readfile;
readfile.open("Profiles.dat",ios::in |ios::binary);
readfile.seekg((profileID-1)*sizeof(newrec),ios::beg);
readfile.read((char *) &newrec,sizeof(Users));
readfile >> newrec->user.Fname;
cout <<newrec->user.Fname;
cout <<"done"<<endl;
getch();
/*readfile.seekg(ios::beg);
static char reader[10];
readfile.read(reader,endloop);
//cout <<reader<<endl;
do
{
//cout << "hello"<<endl;
// getch();
//endloop++;
readfile.read(reader,endloop);
if(reader[10]=' ')
{
// cout <<reader<<endl;
// getch();
}
}while (endloop != 5);
*/
readfile.close();
cout << "Load succesful";
getch();
}