On 6/29/08, John Matthews <[EMAIL PROTECTED]> wrote:

> --- In [email protected], "John Matthews" <[EMAIL PROTECTED]> wrote:
> >
> > --- In [email protected], "Rick Bowers" <Mowgli53@> wrote:
> > >
> > > I am trying to sort an array of pointers to a structure.
> >
> > Hi Rick- below is an example program
>
> Sorry, minor correction:
>
> > static int compareEntryPtr(const void *a, const void *b)
> > {
> >     ENTRY *const *pE1 = a;
> >     ENTRY *const *pE2 = b;
> >
> >     return compareEntry(*pE1, *pE2);
>
> Last line should be:
>
>    return cmpEntries(*pE1, *pE2);
>
> Also, note that 'real' code should check that malloc() doesn't return
> NULL, and in general you should free any malloc()ed memory.


Thanks, John.

I tried compiling your code and got the same basic errors I was getting when
I tried this;
     D:\Work\sorting.cpp In function `int compareEntry(const void*, const
void*)':
39 D:\Work\sorting.cpp invalid conversion from `const void*' to `const
ENTRY*'
39 D:\Work\sorting.cpp initializing argument 1 of `int cmpEntries(const
ENTRY*, const ENTRY*)'
39 D:\Work\sorting.cpp invalid conversion from `const void*' to `const
ENTRY*'
39 D:\Work\sorting.cpp initializing argument 2 of `int cmpEntries(const
ENTRY*, const ENTRY*)'
46 D:\RWBowers\Work\sorting.cpp invalid conversion from `const void*' to
`ENTRY* const*'
47 D:\RWBowers\Work\sorting.cpp invalid conversion from `const void*' to
`ENTRY* const*'

LINE 39 is here:
static int compareEntry(const void *a, const void *b)
{
*   return cmpEntries(a, b);*
}

LINES 46/47 are here:

static int compareEntryPtr(const void *a, const void *b)
{
*   ENTRY *const *pE1 = a;
   ENTRY *const *pE2 = b;*

   return cmpEntries(*pE1, *pE2);



Also,

your approach is to make two calls. I was hoping to do everything in a
single function.

Here is what I tried. Both attempts to point to a structure value (e1 and
e1) fail with "conversion" errors.

int comparefilters (const void *a, const void *b)
{
    int    value;
    struct ENTRY **e1 = a;

// 41 D:\comparefilters.cpp invalid conversion from `const void*' to
`ENTRY**'

    struct ENTRY *e2 = (struct ENTRY *)*b;

// 42 D:\comparefilters.cpp `const void*' is not a pointer-to-object type


    struct ENTRY *b1 = (struct ENTRY *)e1;
    struct ENTRY *b2 = (struct ENTRY *)e2;
    char *c1 = b1->ruleKeyword;
    char *c2 = b2->ruleKeyword;

     return strcmp((char *)c1, (char *)c2);
}

~Rick

> ------------------------------------
>
> To unsubscribe, send a blank message to <mailto:
> [EMAIL PROTECTED]>.Yahoo! Groups Links
>
>
>
>


[Non-text portions of this message have been removed]

Reply via email to