Pointers To Structures Question (qsort)
Stan Brown
stan at Dixie.Com
Sun Mar 3 08:16:36 AEST 1991
I have a problem with a program that I am working on. It compiles
and works correctly, but generates a compiler warning message of the form
warning : structure/union or structure/union pointer required
Since I plan on moving this code to a new machine when I get it I
dam concerned aboyt portabilty.
The environment that I am working in is a version 7 machine (Fortune
32:16 if you ever heard of it).
What rellay pzzles me is that I think there is one more level of
inderction in the compare function than I think is required, yet it works.
If someone could explain my miscomception here, I would greatly
appreciate it.
** The structure
/* structure of fileing location information */
struct file_loc {
char *key;
char *description;
char *long_description;
int qty;
} ;
** The array decleration
main(argc,argv)
int argc;
char *argv[];
{
struct file_loc *array_of_loc_struct[MAX_LOCS];
** The call from main
sort_loc(array_of_loc_struct);
** The call to qsort
void sort_loc(array)
struct file_loc *array[];
{
extern int cmp_loca();
int qty = 0;
while(array[++qty] != NULL) /* Find Qty */
;
qsort(&array[0], qty, sizeof(struct series *), cmp_loca);
}
** The compare function
int cmp_loca(struct1,struct2)
void *struct1;
void *struct2;
{
return strcmp((*(struct file_loc *)struct1)->key, (*(struct file_loc *)struct2)->key);
}
--
Stan Brown P. c. Design 404-363-2303
ateche!sdba!stan "vi forever"
More information about the Comp.lang.c
mailing list