Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with search function

Status
Not open for further replies.

anatazi

Programmer
Jun 24, 2002
33
US
Hi all,
I need to write a function for a program that I am working on. This function takes an int array and a pointer to an array of structures, compares the elements, and writes the matches to another array.
I know that the function would look something like:
Consider that the variables have been declared.

? compare(int Tcard[], people* p)
now should I do 2 for loops
for(i=0; i<numofelem; i++)
{
for(x=0; x<numofleme; x++)
{

if Tcard = people[x].age;
{
/*write to array*/
}
}
}

Any pointers, or help would be appreciated.

 
I dont know exactly what you are trying to achieve,but you could try somthing like this:

struct people
{
int age[14];
int otherArray[14];
const int numofelem;
const int numofleme;
/*other elements*/
};

void Compare( int Tcard[], people* p )
{
int i, x;
for( i = 0; i < p->numofelem; i++ )
{
for( x = 0; x < p->numofleme; x++ )
{
if( Tcard == p->age[x] )
{
/*write to array*/
p->otherArray[x] = p->age[x];
}
}
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top