Totally stuck! I can enter and save info fine(the program only hadnles First names right now, as a test. However, the load function fails.
Ex.
INPUT
Joe
Shmoe
it reads out...
#0
Joe
(it then saves)
#1
Shmoe
(It then Saves)
(The program breaks to menu)
I press L for the login function
it outputs JoeSchmoe as one line, and no matter what I do, I cannot get it to stop reading and outputting the entire file as a single line of text. Any help would be appreciated, the code is below.
Code:#include <stdlib.h> #include <iostream.h> #include <fstream.h> #include <conFX2.h> #include <apstring.h> #include <apstring.cpp> #include <time.h> typedef struct Save { char SaveFname[12]; }data; typedef struct Student { int UserID; char Fname[12]; char Sname[12]; int SepID; } astudent; struct Users { Student user; Users *next; }Userrecord; //userrecord->user.UserID //Userfile subject[25]; //Userfile tsubject; //Function Prototypes data savestudent[25]; data saveAstudent; void NewUser(int i,Users* &head, Users* ¤t_list); void Login(int i,Users* &head); void Save(Users* &head,int i); //done void NewUser(int i,Users* &head, Users* ¤t_list) { char cho; int endloop=0; //apstring Fname; //apstring Sname; //ID; Users *list = new Users, *current_address, *previous_address; current_list=list; cout << "Welcome to the User creation Function"<<endl; cout << "Please answer the following questions."<<endl; for (;; list = list->next) { //add previous addresses etc cout <<"What is your first name? " <<endl; //cout<<endl; cin.getline(list->user.Fname,12); cout <<"\n"; //cout << list->user.Fname<<endl; cout << "Now, your last name"<<endl; cin.getline(list->user.Sname,12); cout <<"\n"; cout << "Finally, enter your ID"<<endl; list->user.UserID=rand(); cout <<"\n"<<"This User has been assigned an ID: "<< list->user.UserID<<"Please remember this number if you wish access this user."<<endl; cout <<"Would you like to make a new User?[Y/N]"<<endl; previous_address=current_address; i++; cho=getch(); if (cho=='n') { //endloop=1; list = previous_address->next = NULL; //delete current_address; break; } else { cout << " Preparing for new entry" <<endl; //getch(); current_address = list->next = new Users; //list=list->next; } }//while(endloop!=1); Save(current_list,i); } void Save(Users* &head,int i) { Users *savelist; ofstream outfile; outfile.open("Profiles.dat",ios::out| ios::app |ios::binary); //savelist=head; //int i=0; int j =0; for(savelist=head;savelist;savelist=savelist=savelist->next) { cout <<j<<endl; strcpy(savestudent[j].SaveFname,savelist->user.Fname); //string copy savelist to struct SAVE //cout <<j<<endl; //outfile << savelist->user.UserID; //outfile <<"name 1" <<savestudent[j].SaveFname<<"*";//<<endl; //outfile<< savestudent[j].SaveFname <<endl; //cout <<"name "<<j<<" :"<<savelist->user.Fname; getch(); outfile<< savestudent[j].SaveFname;// <<endl; cout << savestudent[j].SaveFname <<endl; // outfile << savelist->user.Fname;//<<endl; j++; getch(); } //cout << savelist->user.Fname<<endl; //clrscr(); //j=0; //cout<< savestudent[j].SaveFname <<endl; getch(); //cout<<"2"<<endl; //j=1; //cout<< savestudent[j].SaveFname <<endl; getch(); savelist=NULL; outfile.close(); } void Login(int i,Users* &head) { cout << "login Function " <<endl; Users *loadlist=new Users; ifstream infile; int j=0; cout <<j<<endl; infile.open("Profiles.dat",ios::in| ios::app | ios::binary); //infile.seekg(ios::beg); do { //cout <<"brak"<<endl; //load info INTO new list //infile >> loadlist->user.UserID; infile >> savestudent[j].SaveFname; cout <<j<<endl; //cout << savestudent[j].SaveFname <<endl; getch(); strcpy(loadlist->user.Fname,savestudent[j].SaveFname); cout <<j<<endl; cout << loadlist->user.Fname <<endl; //infile >> loadlist->user.Sname; cout << " where do I crash??" <<endl; loadlist=loadlist->next; j++; cout << " where do I crash??" <<endl; }while(j==1); cout << " Do I break the loop? " <<endl; infile.close(); loadlist=head; for(loadlist=head;loadlist;loadlist=loadlist=loadlist->next) { //cout << loadlist->user.UserID <<endl; cout << loadlist->user.Fname <<endl; //cout << loadlist->user.Sname <<endl; } } char menu() { char ch; clrscr(); gotoxy(15,5); gotoxy(25,7); cout <<"Would you like to...."<<endl; gotoxy(25,8); cout <<"[L]ogin"<<endl; gotoxy(25,9); cout<<"[C]reate a new user"<<endl; gotoxy(25,10); cout<<"[Q]uit?" <<endl; ch = getch(); //ch=toupper(ch); return ch; } void process(char ch,Users* &head) { // Users* list; // static Users* head; static Users* current_list; const int i=0; if(ch == 'c') NewUser(i,head,current_list); else if(ch == 'l') Login(i,head); else if(ch == 's') Save(head,i); } int main() { char ch; Users *head = NULL; head = new(Users); initscreen(); settitlebar("Tutorial"); // textcolor(fgWhite); // textbackground(bgBlue); clrscr(); ch = menu(); while (ch != 'Q') { process(ch,head); ch = menu(); } uninitscreen(); return 0; }



LinkBack URL
About LinkBacks


