0

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;
       
innis
  • 1
  • 3
    The definite answer to the question _How should i resolve this issue?_ is: Debugging. (This is no joke and no sarcasm.) It's very usual that a program doesn't work as expected once it is written and compiles without complaints. The next step is debugging. Hence, debugging is considered as one of the basic necessary skills for S/W development. FYI: [SO: What is a debugger and how can it help me diagnose problems?](https://stackoverflow.com/q/25385173/7478597) – Scheff's Cat Jul 18 '21 at 10:38
  • Please provide sample input and output. Are you entering the title to look up with the same spacing and the same case as it is stored in the array? – Amal K Jul 18 '21 at 16:18

0 Answers0