Simple C++ Project

I am using the C++ function strcmp to compare one string to another. However, I am still not getting my program to print in Oldworld linguistics below. Can you please help?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 #include <iostream>
#include <fstream>
#include <cctype>
#include <iomanip>
#include <string>
using namespace std;

class People{
             int popno;
             char geograpDNA1[50];
             char geograpDNA2[50];
             char lingrup1[50];
             char lingrup2[50];
             public:
             void Oldworld_distribution();
             void Oldworld_linguistics();
};
 void People::Oldworld_distribution(){
     cout<<"Enter the population number of Western Europe "<<endl;
     cin>>popno;
     cout<<"The population of Western Europe is "<<popno<<endl;
 }
 void People::Oldworld_linguistics(){
     cout<<"Enter the linguistics of the area "<<endl;
     cin.ignore();
     cin.getline(lingrup1,50);
     cin.getline(lingrup2,50);
     char strcmp(const char *lingrup1, const char* lingrup2 );
     if (lingrup1 == lingrup2){
          printf("Iberian");
     }
     
 }
int main()
{
   People groups;
   groups.Oldworld_distribution();
   groups.Oldworld_linguistics();
   return 0;
}
Last edited on
Line 28 is a function prototype (which BTW is incorrect).

Line 29: You can't compare two C-strings that way. You are in fact comparing pointers to each string, not the value.

Line 5: Why are you including the C++ string header? You're not using C++ strings. If you were, line 29 would work the way you expect it to.

strcmp requires the <cstring> header.

If you're going to use C-strings, then the proper use of strcmp is:
http://www.cplusplus.com/reference/cstring/strcmp/?kw=strcmp
29
30
31
32
 
  if (strcmp (lingrup1, lingrup2) == 0)  // test for equal
  {  // Do something
  }


Last edited on
Deleted Post. Replicated Answer
Last edited on
tremain7 . You need to understand when you specify the type and when you dont , and like any variable use the name (that what it was meant for)
Topic archived. No new replies allowed.