Hey guys im new to C++ so if this is an dumb question all apologies. Whats going on is i am comparing a user entered major with one from a structure of information on students (name,hours,gpa,etc..). for this im trying to pull out majors in example say someone was a ENG major then it would pull out those students and print some of there cudentials.

Anyways im getting an error of
" cannot convert StudentRecord' to `const char*' for argument `2' to `int strcmp(const char*, const char*)' "
for these two lines
if(strcmp( student.major, studentmajorIn)!=0)
if(strcmp( student.major, studentmajorIn)==0)

any help is very appreciated.

void option5(StudentRecord student[],int n)
 double grade;
 char majorIn[5];
 int i;
cout<<"Enter desired major"<<endl;
cout<<"enter desired GPA"<<endl;

cout<<"Last Name       "<<"First Name      "<<"Hometown         "<<"GPA"<<endl<<endl;

if(strcmp( student[i].major,student[i]majorIn)!=0)
cout<<"No Matches found"<<endl;

if(strcmp( student[i].major, student[i]majorIn)==0)
9 Years
Discussion Span
Last Post by ArkM

The only problem is that theres no majorIn in the structure to begin with if i add it will the structure receive that data and then use it to compare?

also if theres a compare function that is not case sensitive since the (toupper) function wont compile right for me


1. If no majorIn member in a structure, why you wrote senseless and invalid expression student[i]majorIn ? It's simple majorIn argument!
2. What for you wrote the 1st if statement? You don't initialize i at that moment but refer to student[i] ...
3. Why so strange form for(i=0;i<=n-1;i++) ? Keep it simpler: for (i=0; i < n; i++) . Think: it's the same condition!
4. There is case-insensitive non-standard C-string compare function stricmp in some C++ implementations. But it's not so hard to make your own function using toupper. What's a problem?
5. Think about input error handling. Suppose the user types not-a-number instead grade value. Now you can't detect this case.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.