Hi
I'm getting this error for the blue line in the code below: error: cannot convert 'bool' to 'const char*' for argument '1' to 'int strcmp(const char*, const char*)'.
How do I fix it? Please help me. Thanks.
Code:
// read students' record and search for data of a particular student.cpp
// use structure and display all data about the searched student
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
const int C = 3;
struct Student {int rollno; char firstname[20]; char lastname[20]; string sex; float gpa;};
Student stud[C];
int main()
{
int i; char searchname[30];
for (i=0; i<C; i++)
{
cout << "\n\nEnter student #" << (i+1) << "\'s details below\n\n";
cout << "enter roll no.: "; cin >> stud[i].rollno;
cout << "enter first name: "; cin.get(stud[i].firstname, 20);
cout << "enter last name: "; cin.get(stud[i].lastname, 20);
cout << "enter sex: "; cin >> stud[i].sex;
cout << "enter GPA: "; cin >> stud[i].gpa;
}
cout << "enter the name to be searched for: "; cin.get(searchname, 30);
// name to be searched for could be, say, Jack Dawson
for (i=0; i<C; i++)
{
if (strcmp( (stud[i].firstname && stud[i].lastname), searchname ) == 0)
{
cout << "Data for the searched student is shown below\n";
cout << "roll no.: " << stud[i].rollno << endl;
cout << "first name: " << stud[i].firstname << endl;
cout << "last name: " << stud[i].lastname << endl;
cout << "sex: " << stud[i].sex << endl;
cout << "GPA: " << stud[i].gpa << endl;
break;
}
else
{
cout << "Sorry, no student exists with such name" << endl;
break;
}
}
system("pause");
return 0;
}