The better title for this question is to how to pass array to function.
The function in question is incorrect - to force this approach to work we need to change signature - to pass pointer to PPOST. Most likely author of this code relies on idea (not standard) that end of sequence is specified with special value NULL (sentinel), that is for array (allocated for N + 1 pointers) after N not empty elements (pointers to structure) follows N + 1 element (pointer) that will be equal to zero. This zero pointer will mark the end of range. And of course this is responsibility of coder - to mark the end of array of pointers by assigning last element to NULL before calling the function. Do following before calling a function:
// allocate array of pointers
PPOST *ptr = (PPOST*) malloc((N + 1)*sizeof(PPOST*));
ptr + N = NULL; // mark the end - sentinel
POST p;
// ---
compare_post( ptr, p)
// ---
int compare_post( PPOST *pp, POST p)
{
while( *pp ){
if(((*pp)->a == p.a )&&((*pp)->b == p.b )&&((*pp)->c == p.c ))
return 1;
pp++;
}
return 0;
}
You should test the pointer - dereferenced pointer to pointer (*pp) - not value of structure **pp. That is you will iterate through array until you reach N + 1 element.
More common approach (especially widely used in C++ std library) is to pass too pointers to specify boundaries of range: begin of sequence and one past the last: [beg, end). Where end is not included in range. This allows to avoid creating of tedious array of pointers:
// allocate array of struct POST
PPOST ptr = (PPOST) malloc( N * sizeof(POST));
// fill structures
PPOST onePastTheEnd = ptr + N;
POST p;
// ---
compare_post( ptr, onePastTheEnd, p)
// ---
int compare_post( PPOST pp, PPOST end, POST p)
{
while( pp != end ){
if((pp->a == p.a )&&(pp->b == p.b )&&(pp->c == p.c ))
return 1;
pp++;
}
return 0;
}
As soon as we start to change function signature we can also pass the size of the array - this is another approach.