Searching in a file...pls help Urgent! Arun Antony are you there?

User first inputs records into file "gamers.txt". Now i want a search function to input number to be searched from the user and match it with the a record (search)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
class Player
{
 public:
 int num;
 char name[40];
 int age;
 char gname[40];
 float start;
 float end;
 float tprice;
 float dur;
 public:
 void newcus()
 {
  cout<<"Enter new Customer Details:"<<endl;
  cout<<"Customer Number:";
  cin>>num;
  cout<<"Name:";
  gets(name);
  cout<<"Age:";
  cin>>age;
  cout<<"Game:";
  gets(gname);
  cout<<"Start Time:";
  cin>>start;
  cout<<"End Time:";
  cin>>end;
 }
 void tpricer()
 {
  dur=end-start;
  if(dur<=1)
	tprice=2;
  else if(dur>1&&dur<=5)
	tprice=3;
  else if(dur>5&&dur<=7)
	tprice=5;
  else
	tprice=8;
 }
 float returnprice()
 {
  return tprice;
 }
 float returndur()
 {
  return dur;
 }
 void printcus()
 {
  cout<<"\nCustomer Number "<<num;
  cout<<"\nName : ";
  puts(name);
  cout<<"Age : "<<age;
  cout<<"\nGame: ";
  puts(gname);
  cout<<"\nDuration : "<<returndur()<<" hours";
  cout<<"\nPrice : $"<<returnprice();
 }
 void sear(int s)
 {
  file.read((char*)&P,sizeof(P));
  for(int i=0;i<40;i++)
  {
	if(P.num[i]==s)
	 cout<<P[i].putdata();
	else
	 cout<<"\nNo Match Found!";
  }
 }
};

void main()
{
 int op,search;
 char ip;
 Player P[40];
 fstream file("gamers.txt",ios::in,ios::out,ios::app);
 do
 {
  cout<<"\n\n\t\t\tTHE DAILY ARCADE";
  cout<<"\n\t\t\t\tRegister";
  cout<<"\n\n\t\t\t\t1. Customer Entry\n\t\t\t\t2. Customer Exit\n\t\t\t\tSelect option ";
  cin>>op;
  switch(op)
  {
	case 1:clrscr();
			 newcus();
			 file.write((char*)&P,sizeof(P));
			 break;
	case 2:clrscr();
			 cout<<"\nCustomer Number : ";
			 cin>>search;
			 sear(search);
			 break;
	default:cout<<"\nInvalid Choice : ";
			  break;
  }
  cout<<"\n\n\nPress M to return to menu";
  cin>>ip;
 }while(ip=='m'||ip=='M');
 cout<<"\n\nThankyou Come Again";
 file.close();
 getch();
}
Last edited on
Helloo??
great Im still the only one replying to this
So, what is your problem?
void main() --- int main()
Topic archived. No new replies allowed.