15,996,848 members
See more:
have a input string eg "123456789098765432" need to split into two arrays OddArray and EvenArray based on the positionsi.e, all the digits in even position(2,4,6,8....) to EvenArray and all the digits in oddposition(3,5,7...) to OddArray

What I have tried:

C#
```char EvenArray[256],OddArray[256],Inputarray[256];
CString dis = "123456789098765432";
strcpy(Inputarray,dis);
int i,j,k;
int x = strlen(dis);
for(i=0;i<x;i++)>
{
if((i+2)%2 ==0)
{

EvenArray[j]=Inputarray[i];
j++;
}
else
{
OddArray[k]=Inputarray[i];
k++;
}
}```
Posted
Updated 23-Jun-16 16:48pm
v3
jeron1 23-Jun-16 10:13am
Have I completely missed something? You are doing nothing with the CString that supposedly contains the data to be processed, and CString has its own GetLength() method.
Member 11648410 23-Jun-16 22:49pm
strcpy(Inputarray,dis); forgot to add this ..Sorry
jeron1 24-Jun-16 10:31am
Can't you access elements of the CString the same way, with the [] operator? You could get rid of InputArray[], and strcpy(), the variable x, and alter the for loop to look like for(i = 0; i< dis.GetLength(); i++)
phil.o 24-Jun-16 0:23am
For oddity test, I suggest to use `if ((i & 1) == 0)` instead.

## Solution 1

Well... that needs a little tweaking.
You aren't processing it correctly - your definition of "odd" and "even" excludes zero and unity.
Zero I can understand (it's neither odd nor even) but one is odd.
But to exclude them, it's simple: change the initial value of `i`:
C++
`for(i=2;i<x;i++)>`
Should do it.

(Do bear in mind that arrays in C / C++ / C# all start with element at index zero, not index 1: so in the string "12345" the character at index 2 is "3".
If your position values don't allow for that, you need to tweak your code slightly.