I am facing this problem from day 1.
Actually, the book I am reading from has this program written in this way, but when I check it practically on Eclipse IDE, it does not work properly, always showing this error:
invalid conversion from char to const char *
Although I know what the issue is, I don't know how to resolve this problem, and I am facing this problem with every program in which there is some string operation.
The error is with this if
statement:
if(!strcmp(str, *ptr[i]))
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
const char *ptr[10] = { "books", "television", "computer", "sports" };
int i = 0;
char str[25];
cout << "\nEnter your favorite leisure pursuit here :" << "\n";
cin >> str;
for (i = 0; i < 4; i++)
{
if (!strcmp(str, *ptr[i]))
{
cout << "\n your favorite pursuit is available here " << endl;
break;
}
}
if (i == 4)
{
cout << "\n\nYour favorite leisure is not available here" << endl;
}
return 0;
}