About delete function,urgent!

i want to remove a specific data from a txt file, but i can't make it work ,can somebody help me? urgently.Thank you
Last edited on
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstring>
#include<vector>

using namespace std;

typedef struct
{
char location[30];
char IBSN[20];
char author[99];
char title[200];
char edition[30];
char publisher[99];
char price[7];

}book_library;

void menu();
void display_IBSN(book_library record[], char IBSN_no);
void search(book_library record[], char IBSN_no);
void adv_search(book_library record[], int IBSN_no);
int delete_record(book_library record[], char IBSN_no);

int main()
{
book_library record[30];
int choice, IBSN_no = 0;
int i = -1;

ifstream infile("book library.txt");
if (!infile)
{
cout << "Error open input file\n";
return 0;
}
else
{
book_library temp;
int i = 0;

while (infile)
{
infile.getline(temp.location, 20, '\n');
infile.getline(temp.IBSN, 20, '\n');
infile.getline(temp.author, 99, '\n');
infile.getline(temp.title, 200, '\n');
infile.getline(temp.edition, 30, '\n');
infile.getline(temp.publisher, 99, '\n');
infile.getline(temp.price, 7, '\n');

record[i] = temp;
i++;
}
infile.close();
IBSN_no = i;
}
cout << ">>>" << IBSN_no << " DATA INPUT SUCCEEDED <<<" << endl;
while (true)
{
menu();
cout << "Please make choise : ";
cin >> choice;
system("cls");

switch (choice)
{
case 1:
{
display_IBSN(record, IBSN_no);
system("pause");
system("cls");

break;
}
case 2:
{
search(record, IBSN_no);
system("pause");
system("cls");
break;
}
case 3:
{
IBSN_no -= delete_record(record, IBSN_no);
system("pause");
system("cls");
break;
}
case 4:
{
adv_search(record, IBSN_no);
system("pause");
system("cls");
break;
}
case 5:
return 0;
default:
{
cout << "-------Invalid Input.Please enter the correct input(1-4)--------" << endl;
system("pause");
system("cls");
}
}

}
return 0;
}

void menu()
{
cout << "-------------Welcome To Book Search System-------------\n";
cout << "1. IBSN record \n";
cout << "2. Book search \n";
cout << "3. Delete record \n";
cout << "4. Advance Search \n";
cout << "5. Exit \n";
cout << "-------------------------------------------------------\n" << endl;

return;
}

void display_IBSN(book_library record[], char IBSN_no)
{
cout << "---------------Data from file-----------------\n";
cout << fixed << setw(20) << "IBSN No." << setw(30) << "Author"
<< setw(50) << "Title" << endl;
for (int i = 0; i < IBSN_no; i++)
{
cout << setw(20) << record[i].IBSN << setw(30) << record[i].author
<< setw(50) << record[i].title << setw(10) << endl;
}

}

void search(book_library record[], char IBSN_no)
{
char search_title[20];
cout << "Please enter book's IBSN : \n";
fflush(stdin);
cin.getline(search_title, 20);

if (search_title[0] == '0' && strlen(search_title) == 1)
return ;

for (int i = 0; i < IBSN_no; i++)
{
if (strcmp(search_title, record[i].IBSN) == 0)
{
cout << "Location : " << record[i].location << endl;
cout << "IBSN No. : " << record[i].IBSN << endl;
cout << "Author : " << record[i].author << endl;
cout << "Title : " << record[i].title << endl;
cout << "Edition : " << record[i].edition << endl;
cout << "Pulisher : " << record[i].publisher << endl;
cout << "Price : " << fixed << setprecision(2) << record[i].price << endl;
return ;
}
}
cout << "\nBook no found\n";
return ;
}

int delete_record(book_library record[], char IBSN_no)
{

ifstream book_library("book library.txt");
ofstream temp("temp.txt");
int delete_no;
int title,x=0;

cout << "Please get the enter the Book Sequence Number from the list:\n";
cin >> delete_no;

while(book_library>>IBSN_no)
{
if(delete_no!=IBSN_no)
{
temp << book_library << ' ' << title<<endl;
}
if(delete_no==IBSN_no)
{
x=1;
}

}
book_library.clear();
book_library.seekg(0, ios::beg);
book_library.close();
temp.close();
remove("book library.txt");
rename("temp.txt","book library.txt");
if(x=0)
{
cout<<"There are no books that you search"<<endl;
}
if(x=1)
{
cout<<"The book has been deleted"<<endl;
}


return 0;

}

void adv_search(book_library record[], int IBSN_no)
{
int choice, result;
char adv_srh_num[20], adv_srh_name[99],adv_srh_author[99];
char* compare;

while (true)
{
system("cls");
cout << setw(47) << "ADVANCED SEARCH" << endl;
cout << "1 - Search by IBSN \n2 - Search by book's name\n3 - Search by Author\n0 - Return\n";
cout << "Enter your choice: ";
cin >> choice;

switch (choice)
{

case 1:
{
system("cls");
result = 0;
cout << "Please enter a part of IBSN number or full IBSN number: ";
fflush(stdin);
cin.getline(adv_srh_num, 20);
cout << "-----------------------------------------------------------------\n";

for (int i = 0; i < IBSN_no; i++)
{
compare = strstr(record[i].IBSN, adv_srh_num);

if (compare != NULL)
{
cout << "Location : " << record[i].location << endl;
cout << "IBSN No. : " << record[i].IBSN << endl;
cout << "Author : " << record[i].author << endl;
cout << "Title : " << record[i].title << endl;
cout << "Edition : " << record[i].edition << endl;
cout << "Pulisher : " << record[i].publisher << endl;
cout << "Price : " << fixed << setprecision(2) << record[i].price << endl;
result++;
}
}
cout << result << " book found" << endl;
system("pause");

break;
}
case 2:
{
system("cls");
result = 0;
cout << "Please enter a book name(IN CAPITAL LETTER):";
fflush(stdin);
cin.getline(adv_srh_name, 99);

cout << adv_srh_name << endl;;


for (int a = 0; a < IBSN_no; a++)
{
if ((strstr(record[a].title, adv_srh_name)) != NULL)
{
cout << "Location : " << record[a].location << endl;
cout << "IBSN No. : " << record[a].IBSN << endl;
cout << "Author : " << record[a].author << endl;
cout << "Title : " << record[a].title << endl;
cout << "Edition : " << record[a].edition << endl;
cout << "Pulisher : " << record[a].publisher << endl;
cout << "Price : " << fixed << setprecision(2) << record[a].price << endl;
result++;
}
}
cout << result << " book found" << endl;
system("pause");
break;
}
case 3:
{
system("cls");
result = 0;
cout << "Please enter a author name:";
fflush(stdin);
cin.getline(adv_srh_author,99);

cout << adv_srh_author << endl;;


for (int a = 0; a < IBSN_no; a++)
{
if ((strstr(record[a].author, adv_srh_author)) != NULL)
{
cout << "Location : " << record[a].location << endl;
cout << "IBSN No. : " << record[a].IBSN << endl;
cout << "Author : " << record[a].author << endl;
cout << "Title : " << record[a].title << endl;
cout << "Edition : " << record[a].edition << endl;
cout << "Pulisher : " << record[a].publisher << endl;
cout << "Price : " << fixed << setprecision(2) << record[a].price << endl;
result++;
}
}
cout << result << " book found" << endl;
system("pause");
break;
}
case 0:
return;

default:
{
system("cls");
cout << "-------Invalid Input.Please enter the correct input(0-3)--------" << endl;
system("pause");
}
}
}
}
this is my txt file



Sungai Long Campus
9780132990448
Deitel, Paul J.
C : HOW TO PROGRAMMING
7th
Prentice Hall; 7th edition (March 4, 2012)
133.80
Perak Campus
9781844804528
Ward, Patricia
DATABASE MANAGEMENT SYSTEM
1st
Cengage Learning Business Press; 1 edition (July 2, 2006)
91.95
Kuala Lumpur Campus
9780321500465
DeGroot, Morris H., 1931-1989
PROBABILITY AND STASTISTICS
4th
Pearson; 4 edition (January 6, 2011)
160.77
Perak Campus
9781849965217
Ramnath, Sarnath
OBJECT-ORIENTED ANALYSIS AND DESIGN
1st
Springer London; 1 edition (December 6, 2010)
32.05
Kuala Lumpur Campus
9780321635846
Dean Leffingwell
Agile SOFTWARE REQUIREMENT : LEAN REQUIREMENT PRACTICE FOR TEAMS,PROGRAMS,AND THE ENTERPRISE
1st
Addison-Wesley Professional; 1 edition (January 6, 2011)
43.97
Kuala Lumpur Campus
9780672327988
Patton, Ron
SOFTWARE TESTING
2nd
Sams Publishing; 2 edition (August 5, 2005)
31.83
Sungai Long Campus
9780201722192
David Budgen
SOFTWARE DESIGN
2nd
Addison-Wesley; 2 edition (May 15, 2003)
13.79
Perak Campus
9780470518601
Shklar, Leon
WEB APPLICATION ARCHITECTURE : PRINCIPLES, PROTOCOLS, AND PRACTICES
2nd
Wiley; 2 edition (July 5, 2011)
50.76
Perak Campus
9781449647391
Kris Jamsa.
CLOUD COMPUTING : SAAS,PAAS,IAAS,VIRTUALIZATION,MOBILE AND MORE
1st
Jones & Bartlett Learning; 1 edition (March 22, 2012)
90.27
Kuala Lumpur Campus
9780470665763
Yvonne Rogers, Helen Sharp, Jenny Preece
INTERACTION DESIGN: BEYOND HUMAN-COMPUTER INTERACTION
3rd
Wiley; 3 edition (June 7, 2011)
68.19
Perak Campus
9780071633604
Sarang, P. G. (Poornachandra G.)
JAVA PROGRAMMING
1st
McGraw-Hill Osborne Media; 1 edition (February 10, 2012)
31.64
Petaling Jaya Campus
9780201709452
Galin, Daniel
SOFTWARE QUALITY ASSURANCE:FROM THEORY TO IMPLEMENTATION
1st
Addison-Wesley; 1 edition (September 21, 2003)
123.99
Perak Campus
9780071742559
Allen Harper, Shon Harris
GRAY HAT HACKING : THE ETHICAL HACKER'S HANDBOOK
3rd
McGraw-Hill Osborne Media; 3 edition (January 6, 2011)
19.57
Petaling Jaya Campus
9780849309694
Yacoub, Michel Daoud
WIRELESS TECHNOLOGY : PROTOCOLS,STANDARDS, AND TECHNIQUES
1st
CRC Press; 1 edition (December 21, 2001)
220.00
Kuala Lumpur Campus
9780130329509
Burke, J. Richard
NETWORK MANAGEMENT:CONCEPT AND PRACTICE
1st
Prentice Hall (May 10, 2003)
154.80
sUNGAI lONG cAMPUS
9780470038628
Chad Steel
WINDOWS FORENSICS :THE FIELD GUIDE FOR CONDUCTING CORPORATE COMPUTER INBESTIGATIONS
1st
Wiley; 1 edition (May 15, 2006)
29.16
Kuala Lumpur Campus
9780471762935
Yang Bai Jian
MIRCROSOFT SMARTPHONE PROGRAMMING
1st
Wrox; 1 edition (January 3, 2007)
131.58
Petaling Jaya Campus
9780596003098
Liberty, Jesse
PRGRAMMING C#
2nd
O'Reilly Media; Second Edition edition (February 2002)
4.98
Perak Campus
9780195107838
Johnson, James Lee
DATABASE : MODELS,LANGUAGES, DESIGN
1st
Oxford University Press; 1 edition (March 13, 1997)
138.65
Perak Campus
9780521007542
Dudley, R. M. (Richard M.)
REAL ANALYSIS AND DESIGN
2nd
Cambridge University Press; 2nd edition (October 14, 2002)
58.83
Topic archived. No new replies allowed.