Reputation: 1417
I can't seem to get qsort to work in my problem. I look around online and my code should be correct.
int file::compare (const void * a, const void * b)
{
fileinfo* fa = (fileinfo*)a;
fileinfo* fb = (fileinfo*)b;
return (*(int*)fa->inode - *(int*)fb->inode);
}
void file::print()
{
qsort((void *)files, 100, sizeof(fileinfo), compare);
}
files
is an array of fileinfo. struct fileinfo
is a struct that contains the name and inode of a file.
Upvotes: 1
Views: 1348
Reputation: 308216
file::compare
must be declared static
to be used as a parameter to qsort
.
Upvotes: 7