Page 1 of 1

Arrays - question about programming

PostPosted: Tue Feb 08, 2011 8:08 am
by Leif
Hi :D

The question is about arrays. For example we have 2 arrays of int and depending on A and B values we work either with array1[10] or with array2[10].
I have procedure like this:
Code: Select all
void PROC(int A, int B)
{
if (A>B)
{   array1[0]=...;
.....
..... // other actions with array1[];
}

if (A<B)
{ array2[0]=...;
.....
..... // other actions with array2[];
}
}


This is what i want to do:

Code: Select all
void PROC(int A, int B)
{
if (A>B) AAA=array1[10]; // can I do something like this?
if (A<B) AAA=array2[10];

{   AAA[0]=...;
.....
..... // other actions with AAA[];
}



How ?

Re: Arrays - question about programming

PostPosted: Tue Feb 08, 2011 8:32 am
by Bee-Ant
OK, so in this case you have 3 arrays, array1[10], array2[10], and AAA[10].
You seem to already know how to do it though.
Well, this would be my method :
Code: Select all
void InsertValue(int A, int B, int SourceIndex, int TargetIndex, int CheckIndex, int CheckValue)
{
    if(A>B)
    {
        AAA[TargetIndex]=array1[SourceIndex];
    }
    if(A<B)
    {
        AAA[TargetIndex]=array2[SourceIndex];
    }
    if(AAA[CheckIndex]==CheckValue)
    {
        //Do something here
    }
}

Re: Arrays - question about programming

PostPosted: Tue Feb 08, 2011 9:03 am
by Leif
Need some explanations.
Code: Select all
if(A>B)
    {
        AAA[TargetIndex]=array1[SourceIndex];
    }

Does it mean that we assign values from array1 to AAA one by one?

Can we do things like "operate with AAA, but changes are made in array1" just using pointer or other method ?

Re: Arrays - question about programming

PostPosted: Tue Feb 08, 2011 10:27 am
by Bee-Ant
In that case, one by one.

Oh, do you want to include the whole array1 or array2 into AAA?
Then it should be:
Code: Select all
int i;
if(A>B)
{
    for(i=0;i<10;i++)
    {
        AAA[i]=array1[i];
    }
}
if(A<B)
{
    for(i=0;i<10;i++)
    {
        AAA[i]=array2[i];
    }
}

Re: Arrays - question about programming

PostPosted: Thu Feb 10, 2011 8:45 am
by Leif
Thanks, solved )