Listing 6 Retrieving the Keys

/*>>>>>>>>>>>>> Return all keys in AA <<<<<<<<<<<<<<*/
void aa_keys(aa,keys,num)
AA * aa;        /* input -- AA definition */
void ***keys;   /* output -- array of key pointers */
int *num;       /* output -- number of keys returned */
{
  register int i;
  register void **ptr;
  size_t buf_size=aa->current_elements*sizeof(void **);
  
  if (*keys=(void **)malloc(buf_size)) {
     *num=0; ptr=aa->keys;
     for (i=0; i<aa->max_elements; i++,ptr++)
        if (VALID_KEY(*ptr))
          (*keys)[(*num)++]=*ptr;
  } else /* allocation failed */
     *num=-1;
}
/* End of File */