Passing an array to a function:

Hi, I've been trying for hours to find out the error in this program, it has something to do with passing the array to the function, here is the program:
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
#include <iostream>
using namespace std;
bool identical(int, int, int);

void main()
{
	int a[99999], b[99999], n;
	bool check;

	cout<<"Please enter the number of integers per set: ";
	cin>>n;

	cout<<"Please enter the integers of the fist set:\n";
	for (int i=0; i<n; i++)
		cin>>a[i];
	cout<<"Please enter the integers of the second set:\n";
	for (int j=0; j<n; j++)
		cin>>b[j];

	check = identical(a[], b[], n);

	if (check == true)
		cout<<"The two sets are identical";
	else
		cout<<"The two sets are identical";
}

bool identical(int a[], int b[], int n)
{
	bool end = false;
	for (int i=0; i<n; i++)
		if (a[i]!=b[i])
		{
			return false;
			end = true;
		}
	if (end == false)
		return true;
}


And the error is:
........program 3.cpp(20) : error C2059: syntax error : ']'

Also, this is my second C++ code so I'm kind of a no0b :P So please don't overload me with too much tech talk xP
Last edited on
Pass arrays just as anything else identical(a, b, n);
Well I tried doing that, but I get an error :/

...program 3.cpp(20) : error C2664: 'identical' : cannot convert parameter 1 from 'int [99]' to 'int'

Maybe my code is missing a library or something??
Last edited on
Do what bazzy says, plus change your function prototype at the top to include square brackets. Also, you should change main to return int.
It worked! I added square brackets to the prototype and it worked, but I didn't need to change the main to return int.

Thanks guys :) :)
Topic archived. No new replies allowed.