I want to enter a value each time to the originator[] and then delete every time the items in array[]which exist in the originator[]
example: originator[1]={0},array[counter1]={0,1,2} then filtered value should equal{1,2}
example1/originator[2]={0,2},array[counter1]={0,1,2,3} then filtered value should equal{1,3} and so on..
any one can help plz??
int filtered[];
int i2=0;
int originator[6];
originator[i2]=value;//value it varies from time to time {0,1,2,4..}
cout<<"originator has"<<originator[i2]<<endl;
// cout<<"originator has"<<originator[i2-1]<<endl;
i2++;
for(int ii=0;ii<counter1;ii++){//counter1 gives how many item in the array[] defined global ..
for(int i1=0;i1<i2;i1++){
cout<<"orig has"<<originator[i1]<<endl;//
if(array[ii]!=originator[i1])
{
filtered=array[ii];//I think the error is here
...}//if
}//2nd for
}// 1st for
It is also simple enough to do yourself (though much less efficient unless you first sort your arrays as m4ster r0shi did:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
int filter( int* array, int array_size, int* originator, int originator_size, int* filtered )
{
// IMPORTANT: the 'filtered' array MUST BE at LEAST as big as 'array'
// Returns the number of elements placed in the 'filtered' array
int filtered_count = 0;
int* originator_end = originator + originator+size;
for (int aidx = 0; aidx < array_size; aidx++)
{
if (find( originator, originator_end, array[ aidx ] ) == originator_end)
{
filtered[ filtered_count ] = array[ aidx ];
filtered_count += 1;
}
}
return filtered_count;
}
To use it, you must provide enough room for each item:
1 2 3 4 5 6 7 8 9 10
int array[ 10 ] = { 0, 1, 2, 3, 4 };
int array_size = 5;
int originator[ 10 ] = { 2, 3 };
int originator_size = 2;
int filtered[ 10 ];
int filtered_size;
filtered_size = filter( array, array_size, originator, originator_size, filtered );