Passing pointer structure to function?

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
struct Three
{
	string name;
	int num;
	int num2;
};

const int SIZE = 10000;
 Three  Array[SIZE];

void swap(int *Array, int, int);

int main()
{

	ifstream file("C:\\Users\\User\\Desktop\\Array.txt");

	if (!file)
	{
		cout << "File could not be located.";
	}

	for (int x = 0; x < 10000; x++) //Putting them into the array
	{
		file >> Array[x].name;
		file >> Array[x].num;
		file >> Array[x].num2;

		//cout << Array[x].name << " " << Array[x].num << " " << Array[x].num2 << endl; //Displaying the arrays
	}

	
	int low = 0; //First index of the list
	int high = 9999; //Last index of the list

	int largeIndex = 2 * low + 1;
	while (largeIndex <= high)
	{
		if (largeIndex < high)
			if (Array[largeIndex].num < Array[largeIndex + 1].num)
				largeIndex = largeIndex + 1;
		if (Array[low].num > Array[largeIndex].num)
			break;
		else {
			swap(*Array, low, largeIndex);
			low = largeIndex;
			largeIndex = 2 * low + 1;
		}
	}







	return 0;
}



void swap(int *Array, int first, int second)
{
	int temp;
	temp = Array[first];
	Array[first] = Array[second];
	Array[second] = temp;

}




Im having trouble passing an [] to my function I get an error.
How can i successfully pass a structure pointer array to my function?


Last edited on
Your signature for swap is wrong. It should be:
 
void swap(Three *Array, int, int);


PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.


After changing my parameters i get an error on
temp = Array[first];

Error no suitable conversion function from "Three" to "int" exists
Last edited on
Same problem. Array is of type Three. temp is an int.

Change line 64 to:
 
  Three temp;


Ah ok that makes much more sense thank you!
Topic archived. No new replies allowed.