Hi there,
I'm using a large structure, and I want to sort it by one of its members, a double variable.
This is the code I would like to implement:
Code:
//RMSD Sort, this one works OK.
qsort(outlib, structs_len, sizeof(res), struct_cmp_by_rmsd);
//then the structure needs to be re-sorted
qsort(outlib, structs_len, sizeof(res), struct_cmp_by_Model);
These are the definitions I'm using,
Code:
int struct_cmp_by_rmsd(const void *a, const void *b)
{
res *ia = (res *)a;
res *ib = (res *)b;
return (int)(10000.f*ia->rmsd_ext - 10000.f*ib->rmsd_ext);
/* float comparison: returns negative if b > a and positive if a > b. We multiplied result by 10000.0 to preserve decimal fraction */
}
int struct_cmp_by_Model(const void *a, const void *b)
{
res *ia = (res *)a;
res *ib = (res *)b;
return (int *) ( ia->numModel - ib->numModel );
}
after compiling, I get this error:
Code:
sort_structures.h: In function `int struct_cmp_by_Model(const void*, const void*)':
sort_structures.h:19: warning: cast to pointer from integer of different size
sort_structures.h:19: error: invalid conversion from `int*' to `int'
I could not get this one to work, any help would be really appreciated.
Thanks in advance,
Juan Pablo