Problem with a function

Apr 9, 2013 at 2:12am
I'm currently having a problem with the void function getdata in my program I'm writing. I'm not quite sure what I'm doing wrong and I could use some help. I'm a novice at this so I'll try my best to follow any instructions.
Here's my code...

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include <cmath>
#include <string>
#include <iomanip>
#include <fstream>
#include <cstring>

using namespace std;

struct birdlist
{
    string species;
    int birdCount;
};

void getdata (ifstream& inFile,  birdlist [], int& listSize);
void printArray (birdlist list [], int listSize);
void selectionSort( birdlist list[], int listSize);

const int MAX = 200;

string city;
string species;
int birdcount;

int main()
{
    string filename;
    ifstream infile;
    birdlist list [MAX];
    int number;



    cout << "Input the name of the file you wish to open... (followed by txt.)" << endl;
    cin >> filename;


    infile.open (filename.c_str());

    getdata (infile, birdlist, number)

}


void getdata (ifstream infile, birdlist [], listSize)
   {
       string filename;
       string species;
       int birdCount;

       listSize = 200;

       infile >> species;
       infile >> birdcount;

       getline(infile,city);
       cout << city << endl;
       cout << endl;

       while(infile)
    {

        infile >> species;
        infile >> birdcount;

        cout << species << setw(5) << right << birdcount << endl <<endl;

    }
        infile.close ();
    }


 
|41|error: expected primary-expression before ',' token|
Last edited on Apr 9, 2013 at 2:13am
Apr 9, 2013 at 2:18am
I notice that on line 41 you seem to be missing a terminating semicolon.

Also, getdata()'s implementation doesn't match its prototype, and some of the parameters don't have types given.
Apr 9, 2013 at 2:22am
Rookie mistake haha. Well I just fixed those and I'm still getting errors for the getdata function. I feel like I'm implementing it wrong when I call it to int main, but I'm unsure where my problem lies for certain.
Apr 9, 2013 at 2:23am
Post your updated code and all the errors you are getting and we can try to help you understand the error.
Apr 9, 2013 at 2:25am
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include <cmath>
#include <string>
#include <iomanip>
#include <fstream>
#include <cstring>

using namespace std;

struct birdlist
{
    string species;
    int birdCount;
};

void getdata (ifstream infile, birdlist [], int& listSize);
void printArray (birdlist list [], int listSize);
void selectionSort( birdlist list[], int listSize);

const int MAX = 200;

string city;
string species;
int birdcount;

int main()
{
    string filename;
    ifstream infile;
    birdlist list [MAX];
    int number;



    cout << "Input the name of the file you wish to open... (followed by txt.)" << endl;
    cin >> filename;


    infile.open (filename.c_str());
    infile >> species;
    cout << species;

    getdata (infile, birdlist, listSize);

}


void getdata (ifstream infile, birdlist [], int& listSize)
   {
       string filename;
       string species;
       int birdCount;

       listSize = 200;

       infile >> species;
       infile >> birdcount;

       getline(infile,city);
       cout << city << endl;
       cout << endl;

       while(infile)
    {

        infile >> species;
        infile >> birdcount;

        cout << species << setw(5) << right << birdcount << endl <<endl;

    }
        infile.close ();
    }


errors:
1
2
3
4
5
||In function 'int main()':|
|43|error: expected primary-expression before ',' token|
|43|error: 'listSize' was not declared in this scope|
||=== Build finished: 2 errors, 0 warnings (0 minutes, 0 seconds) ===|
Apr 9, 2013 at 2:59am
Straightforward enough. 'listSize' wasn't declared anywhere.
Topic archived. No new replies allowed.