Structs are typically passed by pointer. In the case of struct arrays, it really depends on how you allocate the array. By incrementing a struct pointer, you actually increment the pointer to point to the next struct (the compiler increments it by the sizeof() the struct). EX:
typedef struct _MyStruct
{
int iValue;
char caData[21];
} MyStruct;
MyStruct *StructFcn(MyStruct *spStruct, int iCount);
void PassStructToFcn()
{
MyStruct *spRetval = NULL;
MyStruct sStruct;
sStruct.iValue = 7;
strcpy(sStruct.caData,"Hello");
spRetval = StructFcn(&sStruct,1);
}
void PassStructArrayToFcn()
{
MyStruct *spRetval = NULL;
MyStruct sStruct[3]; // array of 3 structs
sStruct[0].iValue = 2;
strcpy(sStruct[0].caData,"Hello");
sStruct[1].iValue = 3;
strcpy(sStruct[1].caData,"Hello");
sStruct[2].iValue = 7;
strcpy(sStruct[2].caData,"Hello");
spRetval = StructFcn(&sStruct[0],3);
}
MyStruct *StructFcn(MyStruct *spStruct, int iCount)
{
// find the struct who's value is 7
for (int iLup = 0; iLup < iCount)
{
if (spStruct->iValue == 7)
return spStruct;
spStruct++;
}
return NULL;
}
onwards and upwards... -- modified at 12:58 Monday 12th December, 2005