--- ~Rick <[EMAIL PROTECTED]> escreveu:

> I am populating a number of entries and want to sort on the field 
> linedata.transferPath. I'm using qsort and have built a comparator 
> function but cannot figure out how to specify the transferPath 
> element.
> 
> But, I want to sort on an element within a structure. I've tried, and 
> it fails. How can I specify the element to the comparator? (Darn 
> pointers!)? I haven't worked with qsort or comparator functions before.
> 
> int compareEntry (const void * a, const void * b)
> {
>      char *a1    = (char *)a;
>      char *b1    = (char *)b;
>      char *a2    = a1.transferPath;
>      char *b2    = b1.transferPath;
> 
>      return (strcmp((char *)a2, (char *)b2));
> }

  The right code is:

int compareEntry (const void * a, const void * b)
{
     struct ENTRY *e1 = (struct ENTRY*)a;
     struct ENTRY *e2 = (struct ENTRY*)b;
     char *c1  = e1->transferPath;
     char *c2  = e2->transferPath;

     return (strcmp(c1, c2));
}

  You may use typedef struct to do not need to type struct before every
ENTRY.



      Abra sua conta no Yahoo! Mail, o único sem limite de espaço para 
armazenamento!
http://br.mail.yahoo.com/

Reply via email to