void fun()
{
qsort (plist->info, iNum, sizeof (FILEINFO), Compare) ;
}int Compare (const FILEINFO * pinfo1, const FILEINFO * pinfo2)
{
return lstrcmp (pinfo2->szFilename, pinfo1->szFilename) ;
}
为什么编译不过?

解决方案 »

  1.   

    qsort()函数的第一个参数应该是个指针
    void qsort(
       void *base,
       size_t num,
       size_t width,
       int (__cdecl *compare )(const void *, const void *) 
    );
    base 
    Start of target array. 
    num 
    Array size in elements. 
    width 
    Element size in bytes. 
    compare 
    Comparison function. The first parameter is a pointer to the key for the search and the second parameter is a pointer to the array element to be compared with the key. 
      

  2.   

    qsort()函数的第一个参数应该是个指针
    void qsort(
       void *base,
       size_t num,
       size_t width,
       int (__cdecl *compare )(const void *, const void *) 
    );
    base 
    Start of target array. 
    num 
    Array size in elements. 
    width 
    Element size in bytes. 
    compare 
    Comparison function. The first parameter is a pointer to the key for the search and the second parameter is a pointer to the array element to be compared with the key. 
      

  3.   

    qsort ((void*)plist->info, iNum, sizeof (FILEINFO), Compare) ;
      

  4.   

    把第一个参数改成(void*)后依然编译不过错误如下
    E:\VCPROJECT\INTERNET\UPDDEMO\dd.cpp(443) : error C2664: 'qsort' : cannot convert parameter 4 from 'int (const FILEINFO *,const FILEINFO *)' to 'int (__cdecl *)(const void *,const void *)'
            None of the functions with this name in scope match the target type
      

  5.   

    你的比较函数有问题:
    这样改写:int Compare (const void* pinfo1, const  void* pinfo2)
    {
    return lstrcmp ((FILEINFO*)pinfo2->szFilename, (FILEINFO*)pinfo1->szFilename) ;
    }
      

  6.   

    int compare( const void *arg1, const void *arg2 )
    {
       /* Compare all of both strings: */
       return _stricmp( * ( char** ) arg1, * ( char** ) arg2 );
    }
      

  7.   

    int Compare (const FILEINFO * pinfo1, const FILEINFO * pinfo2)
    {
      return _stricmp((FILEINFO *)pinfo2->szFilename, (FILEINFO *)pinfo1->szFilename);
    }
      

  8.   

    (FILEINFO*)大哥,
    按照你的做法改了一下dd.cpp
    E:\VcProject\Internet\UPDDEMO\dd.cpp(454) : error C2227: left of '->szFilename' must point to class/struct/union
    E:\VcProject\Internet\UPDDEMO\dd.cpp(454) : error C2227: left of '->szFilename' must point to class/struct/union
      

  9.   


    int Compare (const FILEINFO * pinfo1, const FILEINFO * pinfo2)
    {
    return lstrcmp (pinfo2->szFilename, pinfo1->szFilename) ;
    }
    ---->
    int Compare (void * pinfo1, void * pinfo2)
    {
    return lstrcmp ((FILEINFO*)pinfo2->szFilename, (FILEINFO*)pinfo1->szFilename) ;
    }