|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript electronics |
c++ - qsort/compare
Hello, I need to sort an array of structures into desending order
by an element declared as a float. Here is my compare function
which im using with Qsort.
----------------------------------------------------------------
int compare_one(const void *v1, const void *v2)
{
int return_value;
return_value = (*(struct proform*)v1).eq_rating - (*(struct
proform*)v2).eq_rating;
if(return_value < 0 )
{
return 28;
}
else if( return_value > 0 )
{
return -34;
}
else
{
return 0;
}
return return_value;
}
-----------------------------------------------------------
This is sorting as if the variables are int's rather than floats,
so the frational part is being ignored.
Question: How do sort on a float variable this is part of a
structure?
Thanks
Paul
Mar 18 2007
Paul skrev:Hello, I need to sort an array of structures into desending order by an element declared as a float. Here is my compare function which im using with Qsort. Mar 18 2007
Hi Bertel, thanks your code works fine. Kind regards Paul Mar 18 2007
|