Compile error for the following program under c++

Hi all,

I compiled following code with problem , I will be very apprecited for your help.

Thanks a lot.
Regards,
Shilunz

#include
#include
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

typedef struct {
int nr;
char name[4];
}tMI;

#define nr_of_months (sizeof(months)/sizeof(months[0]))

int compmi(const void *m1, const void *m2) {
tMI *mi1 = (tMI *) m1;
tMI *mi2 = (tMI *) m2;
return strcmp(mi1->name, mi2->name);

 }

int main(int argc, char **argv) {
unsigned int i;
tMI key;
tMI *res;

        tMI months[] = {
        { 1, "jan" }, { 2, "feb" }, { 3, "mar" }, { 4, "apr" },
        { 5, "may" }, { 6, "jun" }, { 7, "jul" }, { 8, "aug" },
        { 9, "sep" }, {10, "oct" }, {11, "nov" }, {12, "dec" }
   };
        
        
        
        qsort(months, nr_of_months, sizeof(tMI), compmi);
        
        for (i = 1; i < nr_of_months; i++) {
            
             strcpy((char*)key.name,"Jan");
             printf("%s\n",key.name);


	 //result = (char **)bsearch( (char *) &key, (char *)argv, argc,
     //                     sizeof( char * ), (int (*)(const void*, const void*))compare );
             res = bsearch((tMI *)&key, (tMI*)&months[0], nr_of_months,sizeof(tMI), compmi);
             
             if(res == NULL)
                  printf("'%s': unknown month\n", argv[i]);
             else
                  printf("%s: month #%d\n", res->name, res->nr);
        }
        return 0;
   }

when compiled under QNX6.3.0 with c++, the compiled result as below:

make -k CPULIST=x86 EXCLUDE_VARIANTLIST=be/g/ all
make -j 1 -Cx86 -fMakefile all
make[1]: Entering directory C:/QNX630/workspace/qqq/x86' make -j 1 -Co -fMakefile all make[2]: Entering directory C:/QNX630/workspace/qqq/x86/o’
C:/QNX630/host/win32/x86/usr/bin/qcc -Vgcc_ntox86 -c -Wc,-Wall -Wc,-Wno-parentheses -O -DNDEBUG -I. -IC:/QNX630/workspace/qqq/x86/o -IC:/QNX630/workspace/qqq/x86 -IC:/QNX630/workspace/qqq -IC:/QNX630/target/qnx6/usr/include C:/QNX630/workspace/qqq/qqq.cc
C:/QNX630/workspace/qqq/qqq.cc: In function int main(int, char **)': C:/QNX630/workspace/qqq/qqq.cc:63: ANSI C++ forbids implicit conversion from void *’ in assignment
cc: C:/QNX630/host/win32/x86/usr/lib/gcc-lib/ntox86/2.95.3/cc1plus caught signal 33
make[2]: *** [qqq.o] Error 1
make[2]: Target all' not remade because of errors. make[1]: [all] Error 2 (ignored) make[2]: Leaving directory C:/QNX630/workspace/qqq/x86/o’
make[1]: Leaving directory `C:/QNX630/workspace/qqq/x86’

Just like you would have to do with malloc.

res = ( tMI *) bsearch((tMI )&key, (tMI)&months[0], nr_of_months,sizeof(tMI), compmi);

Or even better

res = ( tMI *) bsearch( &key, &months[0], nr_of_months,sizeof(tMI), compmi);

Try this:

	res = (tMI*)bsearch((const void*)&key, (const void*)&months[0], nr_of_months, sizeof(tMI), compmi);

Hi Mario & RoverFan,

  Thanks many for your help. I got it.

cheers,
shilunz