Problem with pointers

I am encountering a problem with the pointers in my program. I think I might have declared or implemented them wrong, as we just learned about them in class.

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
74
75
76
77
78
79
80
#include <iostream>
#include <cmath>
#include <string>
#include <iomanip>
#include <fstream>
#include <cstring>

using namespace std;
////structs/////
struct birdlist
{
    string species;
    int birdcount;
};
 birdlist birds;
 birdlist *birdies;

///////consts///////
const int max_size = 200;
/////prototypes//////
void getdata (ifstream& inFile,  birdlist [], int& listSize);
////variables///////
string city;

////////main///////////
int main()
{
birdies = &birds;
birdlist list [max_size ];
ifstream datafile;
int number;




string filename;

cout << "Input the file you wish to open..." << endl;
cin >> filename;


datafile.open(filename.c_str());
if (!datafile)
{
    cout << "File not found..." << endl << endl;

    return 1;
}

getdata(datafile, *birdies , number);

}


void getdata (ifstream inFile, birdlist [], int& listSize)
   {
       char selection;
       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 ();
    }


The error is:
|50|error: cannot convert 'birdlist' to 'birdlist*' for argument '2' to 'void getdata(std::ifstream&, birdlist*, int&)'|
Last edited on
The function 'getdata(...)' expects either an array or a pointer to an array. You shouldn't be dereferencing birdies when you pass it to this function.
When I change the 2nd argument to birdlist, the array of structs i am using, I get the error...
 
|50|error: expected primary-expression before ',' token|


Topic archived. No new replies allowed.