Click here to Skip to main content
15,889,822 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
in my resume builder application, i am trying to read specific data from binary file.
bt it is just displaying first record of a file

please help me out

here is my code

C++
class company
{

	char cmp_id[10];
	char cmp_nm[100];
	char addrs[100];
	char city[100];
	char state[100];
	char vacancy[100];
	char req_skill[100];
	char c_eml[100];
	char c_pwd[10];

	public:

	
	 void add();
	 void disp();
	
	 friend class admin;

	void getdata()
	  {

		     company obj;
		     cout<<"\nEnter Your  Company Id. ";
		     fflush(stdin);
		     v_id(cmp_id , num);

		     cout<<"\nEnter The Company Name : ";
		     gets(cmp_nm);
		     fflush(stdin);
		     //  v_name(cmp_nm,min);

		     cout<<"\nEnter The Address :";
		     gets(addrs);
		     fflush(stdin);

		     cout<<"\nEnter City : ";
		     gets(city);
		     fflush(stdin);

		     cout<<"\nEnter vacancy :";
		     gets(vacancy);
		     fflush(stdin);


	  }

	  void showdata()
	  {

		cout<<cmp_id<<"\t"<<cmp_nm<<"\t"<<addrs<<"\t"<<city<<"\t"<<state<<"\t"<<vacancy<<"\t"<<req_skill<<"\t"<<c_eml<<"\n";

	  }


	  char *getid()
	  {
		return cmp_id;
	  }

};


void admin :: search_cmp()
{
    company cmp_obj;

    fstream f;
    int ch;

    char c_nm[100];
    char c_ct[100];
    char c_vac[100];

    clrscr();
    f.open("company.dat",ios :: binary | ios ::in);
    f.read((char*)&cmp_obj,sizeof(cmp_obj));

    do
    {

    cout<<"\n\t 1]. Company By Name";
    cout<<"\n\t 2]. Company By City";
    cout<<"\n\t 3]. Company By Vacancy";
    cout<<"\n\t 4]. Back";

    cout<<"\n\t Enter Your Choice :";
    cin>>ch;

    switch(ch)
    {
	case 1:
		cout<<"\n Enter Company city :";
		cin>>c_ct;
                while(!f.eof())
                {
		if(strcmp(c_ct,cmp_obj.city))
		{
			cmp_obj.showdata();
		}
                }
		break;
	
	case 4:
		cout<<"\nPress Any Key To Continue ";

		break;

    }
    }while(ch!=4);

}
Posted
Updated 2-Jul-14 6:19am
v3

1 solution

You only load one company record (with the fread function), so only one can be displayed.
Apart from that, there are a bunch of true horrors in your code, but I'll leave it as an exercise to the reader to find out which.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 2-Jul-14 15:29pm    
Agree, a 5. ;-)
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900