Returning an array

Hi all,

I have googled about this problem, I know that there are a lot of question about this but I can't still work out.

I have an array of integer at the first place, the question is to find all the even number in that array. Here is my code:
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
// MAIN FUNCTION
void main()
{
int a[100], aeven[100];
/*
...Statements...
*/
aeven[100] = alleven(a, n);
}

// FIND ALL EVEN FUNCTION
int alleven(int a[], int n)
{
	int aeven[100];
	int i, j=0;
	for(i=0;i<n;++i)
	{
		if(a[i]%2==0)
		{
			aeven[j]=a[i];
			++j;
		}
	}
	return aeven;
}


It doesn't work, how can I return the aeven from the alleven function to the aeven in the main ?

Thanks.
Last edited on
If you pass an array to a function, it is automatically passed by reference. So what ever changes are made to the array within the function, they remain changed in the function that called it.
provide both arrays as parameters to the 'alleven()' function
Topic archived. No new replies allowed.