I am working on a Library Management system using C++, but while trying to search a book by its title, the output prints 'No records found' even when the book was entered. How should i resolve this issue?
#include <iostream>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
using namespace std;
struct library
{
char title[30];
char author[30];
int price;
int numberofcopies;
};
int b;
library librarybooks[50];
int main()
{
int choice;
while(true)
{
cout<<"\n***********LIBRARY MANAGEMENT SYSTEM***********\n\n";
cout<<"1- Enter the book details\n";
cout<<"2- Display the book list\n";
cout<<"3- Search a book by it's name\n";
cout<<"4- Search a book by author\n";
cout<<"5- Sort the books\n";
cout<<"6- Exit\n";
cout<<"\nPlease enter your choice: ";
cin>>choice;
Search function:
case 3:
char bookname[30];
int i;
cout<<"Enter the book title: ";
cin>>bookname;
for(int i=0;i<b;i++)
{
if(strcmp(bookname,librarybooks[i].title)==0)
{
cout<<"\nBook Name: \n"<<librarybooks[i].title;
cout<<"\nCopies Available: \n"<<librarybooks[i].numberofcopies;
}
else
{
cout<<"No records found";
}
}break;