Array, file input, sorting functions

i have data from an inputted data.
the file consists of a list of name and score
e.g. Sarah 89

i want to sort the list according to the scores. i have something that works within the int main() but i cant seem to make an external function for it because i think im not declaring the array properly.

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

void sortscore(string stuName[], double score[], int M)
{
	string tempname;
	double tempscore;
	int i, j;

	for ( i = 0; i < M-1; ++i )
	{
		for (j = i+1; j < M; ++j)
		{
			if(score[i] < score[j])
			{
				tempscore= score[i];
				score[i] = score[j];
				score[j] = tempscore;

				tempname = stuName[i];
				stuName[i] = stuName[j];
				stuName[j] = tempname;
			}
		}
	}

int main()
{
...


sortscore(student[].name, totalscore, M); // THE PROBLEM IS HERE ?
...}



thank you in advance.
Last edited on
You should call your function as: sortscore(student, totalgpa, M);
And change your function a little:
1
2
3
4
5
void sortscore(Student /*Or whatever type your array is*/ students[], double score[], int M)
/*...*/
    tempname = students[i].name;
    students[i].name = students[j].name;
    students[j].name = tempname;
Last edited on
Topic archived. No new replies allowed.