At Friday 1/25/2008 07:55 PM, you wrote:
>--- ~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.

Thank you. This seems to have done the trick. I 
just couldn't seem to get my thoughts focused enough to get this correct.

I had tried the struct->element as well as 
struct.element formats but couldn't seem to get the right combination.

Thanks again.

~Rick



>       Abra sua conta no Yahoo! Mail, o único 
> sem limite de espaço para armazenamento!
>http://br.mail.yahoo.com/
>
>
>To unsubscribe, send a blank message to 
><mailto:[EMAIL PROTECTED]>.
>Yahoo! Groups Links
>
>
>

Reply via email to