expected primary-expression before

How do i fix this error: pig.cpp:18: error: expected primary-expression before ‘sentance’

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 13 int main (int argc, char *argv[])
 14 {
 15 
 16    string sentence;
 17 
 18    pigl(string sentance);
 19 
 20    if (argc != 2)
 21    {
 22       cout << "useage: ./pig [string of text]" << endl;
 23       return 0;
 24    }
 25    while (--argc) pigl (*++argv);
 26    return 0;
 27 }
when you call a function you put the variable name not the variable name and type. If you put the variable name and type then you are by definition defining a new variable when you really want to use the old one. Also you spelled sentence wrong on line 18 it should be spelled how it is on line 16.

Also line 25 looks like an infinite loop to me. Maybe you want it to loop while argc is greater than 0?

*edit fixed type
Last edited on
I've changed it to this, but i see a new error:

pig.cpp:10: error: too few arguments to function ‘std::string pigl(std::string)’
pig.cpp:18: error: at this point in file

Also, how would you loop line 25 like you suggested?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  7 using namespace std;
  8 
  9 bool isvowel(char);
 10 string pigl(string);
 11 string rotate(string);
 12 
 13 int main (int argc, char *argv[])
 14 {
 15 
 16    string sentance; //spelled sentence wrong the whole time so im gonna go with it
 17 
 18    pigl();
 19 
 20    if (argc != 2)
 21    {
 22       cout << "useage: ./pig [string of text]" << endl;
 23       return 0;
 24    }
 25    while (--argc) pigl (*++argv);
 26    return 0;
 27 }
On line 18, you want to supply "sentance" to your function, like so:
 
pigl(sentance);


Also, your while(--argc) code is fine, if a bit weird. For anyone who doesn't understand it, it is looping through, subtracting one each time. The "while" loop tests if it is true (non-zero) or false (zero), and the loop ends when argc reaches 0, allowing the loop to finish.
I'm compiling correctly now, thank you for your help.
Topic archived. No new replies allowed.