View Single Post
  #1 (permalink)  
Old February 14th, 2008, 09:48 AM
unpopular unpopular is offline
Registered User
 
Join Date: Feb 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default cin.getLine() function skips. Please help!

When I run the programme of which this function is a part, the programme changes the land line phone number and cellular phone number but not the name, address and email. It just jumps to the next line. the cin.getLine() has problem.

void directory::modification()
{

      clrscr();

      cout<< "\n\t @@@@@@ @@@@@ @@@@@ @@@@@@ @@@@@ @ @ @@@@@@ ";
      cout<< "\n\t=====@ @ @ @ @ @ @@ @ @ =====";
      cout<< "\n\t=====@@@@@@ @ @ @ @ @ @ @ @ @ @@@ =====";
      cout<< "\n\t=====@ @ @ @ @ @ @ @@ @ @ =====";
      cout<< "\n\t @@@@@@ @@@@@ @@@@@ @ @@@@@ @ @ @@@@@@ \n\n\n\n";
      long pn;
     int n,i;
     ifstream inFile;
     ofstream outFile;

     inFile.open("addressesFile");
     if(!inFile)
     {
         cout<<"\n File not found!";
         outFile.close();
         exit(-1);
      }
    outFile.open("new");
    n=test();
    if(n==0)
    {
        cout<<"\n The file is empty. ! ";
        getch();
        return;
    }


   for(i=0;i<n;i++)
      {
          inFile.read((char*)&obj,sizeof(obj));
          outFile.write((char*)&obj,sizeof(obj));
      }
      inFile.close();
      outFile.close();
      outFile.open("addressesFile",ios::trunc);
      inFile.open("new");
      if(inFile.fail())
      {
          cout<<"\n The file was not found ! ";
          getch();
          return;
      }
   char ch;
   cout<<"\n Enter the Land Line Phone Number of the Contact :";
   cin>>pn;
   ch=cin.get();
   //cin.get(ch);
   for(i=0;i<n;i++)
    {
       inFile.read((char*)&obj,sizeof(obj));
       char d;
       if(pn==landLinePhone)
          {
            cout<<" Name : "<<obj.contactName<<"\n";
            cout<<" Home Address : "<<obj.homeAddress<<"\n";
            cout<<" EMAIL ADDRESS : "<<obj.email<<"\n";
            cout<<" Cellular Phone Nmber : "<<obj.cellularPhone<<"\n";
            cout<<" Land Line Phone Number : "<<obj.landLinePhone<<"\n\n";

            d=check("HOUSE PHONE NUMBER ");
            if((d=='y') || (d=='Y'))
            {
                cout<<"\n Enter the new land line phone number of the contact, please. :";
                cin>>landLinePhone;
                ch=cin.get();
                //cin.get(ch);
            }
            d=check("OFFICE PHONE NUMBER ");
            if((d=='y') || (d=='Y'))
              {
                cout<<"\n Enter the new cellular phone number of the contact, please. :";
                cin>>cellularPhone;
                ch=cin.get();
                //cin.get(ch);
              }
              d=check("Name of the Contact");
            if((d=='y') || (d=='Y'))
            {
                cout<<"\n Enter the name of the contact, please. : ";
                cin.getline(contactName,20,'\n');
                //cin.get();
              }
            if(check("HOME ADDRESS")=='y')
            {
                cout<<"\n Enter the new Home Address of the contact, please. :";
                cin.getline(homeAddress,50,'\n');
                //cin.get();
            }
            if(check("EMAIL ADDRESS:")=='y')
            {
                cout<<"\n Enter the new E-mail Address of the contact, please. :";
                cin.getline(email,25,'\n');
                //cin.get();
            }
       }//the outer if ends here.
       outFile.write((char*)&obj,sizeof(obj));
    }
    outFile.close();
    inFile.close();
}

Reply With Quote