delete function not working

Q) I have made a project on airline management.In this my delete function is not working. On using the function the program exits and when we use display all button after deleting it goes in a loop.
If you want i can give you the whole project.

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

// delete
void deletedata()
{
clrscr();
fstream fin,fout;
fin.open("airdata",ios::binary|ios::in);
fout.open("temp",ios::binary|ios::out);
char fno[20];
int found=0;
int confirm=0;
cout<<"flight no : \t";
cin>>fno;
fin.read((char*)&m,sizeof(m));
while(fin)
	{
	if(!strcmp(m.getflightno(),fno))
	{
	m.show();
	found=1;
	cout<<"want to delete";
	cin>>confirm;
	if(confirm==0)
	fout.write((char*)&m,sizeof(m));
	}
	else
	{
	fout.write((char*)&m,sizeof(m));
	}
	fin.read((char*)&m,sizeof(m));
	}
if(found==0)
{
cout<<"not found";
exit(0);
}
fin.close();
remove("airdata");
rename("temp","airdata");
getch();
}

void main()
{
clrscr();
int choice=0;
while(choice!=7)
{
clrscr();
cout<<"\t \t ************************************** \n";
cout<<"\t \t welcome to online airline reservation \n ";
cout<<"\t \t ************************************** \n" ;
cout<<"\t \t \t 1. reservation \n";
cout<<"\t \t \t 2. display all\n";
cout<<"\t \t \t 3. display a record \n";
cout<<"\t \t \t 4. modify a record \n";
cout<<"\t \t \t 5. list of flight \n";
cout<<"\t \t \t 6. delete \n ";
cout<<"\t \t \t 7. exit \n";
cout<<"\t \t \t enter your choice \n \t \t \t \t";
cin>>choice;
switch(choice)
{
case 1:
{addrecord();
generate();}
break;

case 2: displayall();
break;

case 3: disparecord();
break;

case 4:  modifyrecord();
break;

case 5: enquiry();
break;

case 6: deletedata();

case 7: exit(0);
default:
cout<<"choice entered is wrong";
}
}
getch();
}
class xii cbse in india?
use this logic:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void deleteItem(char name[]){
	int flag=0;
	ifile.open("shop.dat");
	ofile.open("temp.dat",ios::app);
	while(ifile.read((char *)&thing,sizeof(thing))){
		if(strcmpi(thing.retName(),name)!=0){
			ofile.write((char *)&thing,sizeof(thing));
			flag++;
		}
        }
        if(flag==0)
               cout<<"\nUnable to delete...Aborting Delete!";
        else
               cout<<"\nDeleted!";
        ifile.close();
        ofile.close();
}


1.I have passed the name of the item as a parameter..u may change it
Last edited on
yes...
kk will try
Topic archived. No new replies allowed.