file problem

This is my create function in server program.It is receiving the object accurately cuz when I call show_details() it shows all the values correctly but is not writing the object in file.My file do not exist in disk so i expect the program to create it by itself.

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
void create()
{
cout<<"\nReached create";
fflush(stdin);
account new_acc,temp;
int create_stat;
ifstream f1;
ofstream f2;
cout<<"\nAbout to recv";
recv(lsocket,(char*)&new_acc,sizeof(new_acc),0); 
new_acc.show_details();
f1.open("F:\PRASHANT'S DOCUMENT\projects\class xii\NETWORK\BANKING\BANK.PG");
f2.open("F:\PRASHANT'S DOCUMENT\projects\class xii\NETWORK\BANKING\BANK.PG",ios::app);
while(1)
{
f1.read((char*)&temp,sizeof(temp));
if(!f1)
{
cout<<"File does'nt exist";
}
else
{
if(strcmp(new_acc.ret_acc_no(),temp.ret_acc_no())==0)
{
create_stat=0;
for(i=0;i<500;i++)
sendbuffer[i]=0;
strcpy(sendbuffer,(char*)&create_stat);
send(lsocket,sendbuffer,500,0);
return;
}
if(f1.eof())
{
break;
}
}
}
f2.write((char*)&new_acc,sizeof(new_acc));
create_stat=1;
for(i=0;i<500;i++)
sendbuffer[i]=0;
strcpy(sendbuffer,(char*)&create_stat);
send(lsocket,sendbuffer,500,0);
}
It's hard to follow the bolck structure of you function without proper indentation.

what i see is on line 30: the function ends there.

the other issue is: what is account? Be aware that it must not contain pointer (directly or indirectly (via other classes/structs)
sorry I didn't intended the code. account is a class that contains the informatiion about a bank account.
Topic archived. No new replies allowed.