The question is check whether a particular book is found or not in a list of books. I know how to do directly but need to use pointer. Please help me to debug the second code.
#include <iostream>
#include<string.h>
using namespace std;
int main()
{
int n,i,c=0;
char A[10][100],s[10];
cout<<"Enter no:of books: ";
cin>>n;
for(i=0;i<n;i++)
cin>>A[i];
cout<<"Enter book you want to search: ";
cin>>s;
for(i=0;i<n;i++)
{
if(strcmp(A[i],s)==0)
c++;
}
if(c==0)
cout<<"Not found";
else
cout<<"Book found";
}
I want to do this using pointer. Kindly help me
I tried this:
#include <iostream>
#include<string.h>
using namespace std;
int main()
{
int n,i,c=0;
char A[10][100],s[10];
const char *p[10][100];
cout<<"Enter no:of books: ";
cin>>n;
for(i=0;i<n;i++)
cin>>A[i];
cout<<"Enter book you want to search: ";
cin>>s;
p=&A[0];
for(i=0;i<n;i++)
{
if(strcmp(*p,s)==0)
c++;
p++;
}
if(c==0)
cout<<"Not found";
else
cout<<"Book found";
}
But not working