# Thread: Help with field index!

1. ## Help with field index!

I need to put numbers from fieldA to even indexes of fieldC, and numbers from fieldB to uneven indexes of fieldC. Im just going in circles, need some hints! I filled up fieldC with nums from A and B but dont know how to sort them like this.

need this: 1. fieldA, 2. fieldB, 3.fieldA, 4. fieldB...

2. I really don't understand what you mean by field index... and btw, the plural of index is indices.

QuantumPete

3. I have an array of 10 elements. I created it from an 2 arrays of 5 elements each. I have array 'A' which is filled up with elements from arrays 'B' and 'C'.

A1.B1
A2.B2
A3.B3
A4.B4
A5.B5
A6.C1
A7.C2
A8.C3
A9.C4
A10.C5

And I need array 'A' to have array 'B' on its even indices and array 'C' on its uneven indices.

A1.C1
A2.B1
A3.C2
A4.B2.....

4. aha! That makes more sense. There's literally tons of ways of doing this.
You can use one loop and mod the counter to see whether it's even or odd.
You could use two loops and multiply the counter by 2 when assigning to A and for one of the loops you add one for the other you don't.
That should get you started. Knock up some code and post it here and then we can discuss what else needs to be done.

QuantumPete

5. Code:
```#include <stdio.h>

#define N 5

int main()

{
int sranje;
int prvi[N];
int drugi[N];
int a;

for(a=0;a<N;a++)
{
printf("%d. = ",a+1);
scanf("%d", &prvi[a]);
}

printf("\n");

for(a=0;a<N;a++)
{
printf("%d. = ",a+1);
scanf("%d", &drugi[a]);
}

function(prvi, drugi);

scanf("%d", &sranje);

}

int function(int prvi[N], int drugi[N])
{
int *treci, M,a,k=0;
M=N+N;

treci=((int*)malloc(sizeof(int)*(M)));

for(a=0;a<N;a++)
{
treci[k]=prvi[a];
k++;
}
for(a=0;a<N;a++)
{
treci[k]=drugi[a];
k++;
}

for(a=0;a<M;a++)
{
printf("\n%d. = %d", a+1, treci[a]);
}

}```
I have this...

i tried
Code:
```for(a=0;a<N;a++)
{
if(a%2==0)
{
treci[k]=prvi[a];
}
k++;

}```
, or putting
Code:
```for(a=0;a<N;a++)
{
treci[k]=prvi[a];
k++;
a++;
}```
to skip one extra number but nothing, I think it shoul be there somewhere..

6. Code:
```#include <stdio.h>
#include <string.h>
int main()

{
int sranje;
int prvi[]={'2','2','2'};
int drugi[]={'5','5','5'};
int *pp,a,*pd,*pt;
int treci[6];
pp=prvi;
pd=drugi;
pt=treci;

for(a=0;a<3;a++)
{
printf("%3d", pp[a]);
}
printf("\n");
for(a=0;a<3;a++)
{
printf("%3d", pd[a]);
}
for(a=0;a<6;a++)
{
pt=pp;
pt++;
pt=pd;
}
for(a=0;a<6;a++)
{
printf("\n %d.= %d",a+1, pt[a]);
}

scanf("%d", &sranje);
}```
or something like, this, but it gives me strange output....50,53...

7. Code:
```		for(a=0;a<6;a++)
{
pt=pp;
pt++;
pt=pd;
}```
What's this supposed to do?

Because it doesn't appear to me that it does anything. Each loop takes the copies the value of pp into pt, then adds one to pt, then copies pd into pt - the changed pt is not used.

--
Mats

8. Code:
```	for(a=0;a<6;a++)
{
for(b=0;b<3;b++)
{
pt[a]=pp[b];

}
a++;

}```
now, i managed to put pp into pt in every other element, still need to put pd in.

9. Code:
```#include <stdio.h>
#include <string.h>
int main()

{
int sranje;
int prvi[]={'2','2','2'};
int drugi[]={'5','5','5'};
int *pp,a,*pd,*pt,b;
int treci[6];
pp=prvi;
pd=drugi;
pt=treci;

for(a=0;a<3;a++)
{
printf("%3d", pp[a]);
}
printf("\n");
for(a=0;a<3;a++)
{
printf("%3d", pd[a]);
}
for(a=0;a<6;a++)
{
for(b=0;b<3;b++)
{
pt[a]=pp[b];

}
a++;
}
for(a=1;a<6;a++)
{
for(b=0;b<3;b++)
{
pt[a]=pd[b];

}
a++;
}
for(a=0;a<6;a++)
{
printf("\n %d.= %d",a+1, pt[a]);
}

scanf("%d", &sranje);
}```
I did it!!!! HURA!!!!!!!