error int[int]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...

void split(const int array[],int length,int & even_array,int even,int & odd_array,int odd)
{

  int count_even(0); 
  int count_odd(0); 

  for (int i=0; i<length;i++)
  {
	if(array[i]%2==0)
	{
		even_array[count_even] =array[i];
		count_even++;
	}else
	array_odd[count_odd]=array[i];	
	count_odd++;  
  }
	
}

...


example, if user input 10 number, (say 1-10), my program will count even number,and odd number in the array, and then assign as as even & odd.
which will make even = 5 and odd =5.

so i will have 3 array, original list,(10 elements). odd_array(5 elements) and even_array(5 elements).

i am trying to copy even element from original list, and assign it into even_array and the odd element to the odd_array.

the problem is I got invalid types ‘int[int]’ for array subscript. (in line 13&16)

I have all sorted out, except this part.
even/odd_array are, despite their names, not arrays. There are references to single integers. Did you mean to use int*?
yea.. i was learning pointer at this time...

and even/odd_array are indeed a pointer. however, i do not know how to fixed it..
You say they are pointers, but they aren't declared as such. That's why you are getting errors. Try changing their types.
yeah.. i change it into pointer and it works.. thanks..
Topic archived. No new replies allowed.