samedi 5 janvier 2019

How to fix the double output of a single entry in a file?

This is the function to write the record in a file.

void getfadata()
     {
         cout<<"\nEnter the Faculty Name : ";
         gets(name);
         cout<<"\nEnter the Faculty ID/Roll no. : ";
         cin>>rollno;
         cout<<"\nEnter the Faculty Father's Name : ";
         gets(fname);
         cout<<"\nEnter the Mobile No. : ";
         gets(mobile);
         cout<<"\nEnter the E-Mail ID : ";
         gets(mail);
         cout<<"\nEnter the Total Subjects : ";
         cin>>totsub;
         //cout<<"\nThe total subjects chosen are : "<<totsub;
         for(int i=0;i<totsub;i++)
         {
             cout<<"\nEnter the Subject "<<i+1<<" Name : ";
             cin>>subject[i];
         }
         pass:
         cout<<"\nCreate Your Login Password "
          "(Password should be of 10 characters.) : ";
         int k;
         for(k=0;k<10;k++)
         {
             passwd[k]=getch();
             cout<<"*";
         }
         getch();
         cout<<"\nRe-Enter the above password : ";
         for(k=0;k<10;k++)
         {
             repasswd[k]=getch();
             cout<<"*";
         }
         getch();
         if(strcmp(passwd,repasswd)==0)
         {
             cout<<"\nEnter the Unique Keyword to Recover Password : ";
             cin>>rpasswd;
             cout<<"\n\nPlease note your UserName and ID/Roll no. \n";
         }
         else
         {
             cout<<"\nPassword do not match."<<endl;
             char t;
             cout<<"\nDo you want to try again (y/n) : ";
             cin>>t;
             while(t=='y'||t=='Y')
                goto pass;
         }
     }

This function displays the record.

if(tmp==3)
        {
            ifstream fs;
            fs.open("fainfo.txt",ios::in);
            fs.seekg(0);
            while(!fs.eof())
            {
                fs.read((char *)&a,sizeof(Admin));
                a.fadisplay();
            }
            fs.close();
        }

I expect the output to be: Faculty Name : Bhavesh Faculty ID/Roll No. : 101 Faculty Father's Name : Abhay Faculty Mobile No. : 123456789 Faculty E-Mail ID : abcd34@gmail.com Faculty Subjects : 2 Subject 1: Maths Subject 2: Science But the actual output is: Faculty Name : Bhavesh Faculty ID/Roll No. : 101 Faculty Father's Name : Abhay Faculty Mobile No. : 123456789 Faculty E-Mail ID : abcd34@gmail.com Faculty Subjects : 2 Subject 1: Maths Subject 2: Science
Faculty Name : Bhavesh Faculty ID/Roll No. : 101 Faculty Father's Name : Abhay Faculty Mobile No. : 123456789 Faculty E-Mail ID : abcd34@gmail.com Faculty Subjects : 2 Subject 1: Maths Subject 2: Science

Aucun commentaire:

Enregistrer un commentaire