Expected Primary-expression

I keep getting the error "error: expected primary-expression before ',' token" when there is clearly a comma there. What am I missing?

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
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

struct student
{
    string lname, fname;
    int ascore[5];
    double average;


};
void selectSort(student & , int); //this is the prototype. 
void getData(int &, student A[], ifstream &);
const int ARSIZE=20;
int main ()
{
  student astudent[ARSIZE];
    int dataSize;
    string fileName;
    ifstream userFile;
    cout<<"Enter a file name."<<endl;
    getline(cin,fileName);
    userFile.open(fileName.c_str());
    getData(dataSize, astudent, userFile);
    cout<< "Data size is "<<dataSize<<endl;
    selectSort(astudent &, dataSize); //This is where the error is.
    userFile.close();
    return 0;
}

void getData(int & count, student arr[], ifstream & userFile)
{
    count=0;
    while(count<ARSIZE && userFile>>arr[count].lname)
        {
            userFile>>arr[count].fname;
                for(int i=0; i<count; i++)
                    userFile>>arr[count].ascore[i];
            count++;
        }


}

void selectSort(student astudent[] , int limit) //This is the subfunction.
{
    int maxLoc;
    for(int top=0; top<limit-1; top++)
 {
        maxLoc=top;
        for(int i=top+1; i<limit; i++)
        {
            if(astudent[i].ascore>astudent[maxLoc].ascore)
                maxLoc=i;
        }
        if(maxLoc!=top)
            swap(astudent[maxLoc], astudent[top]);
    }

}
You don't need the reference (&) symbol, since you already declared that part in your prototype function right below your struct.

Just get rid of the & symbol on line 28.
Gotcha. Thanks:)
Topic archived. No new replies allowed.