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.
file::comparemust be declaredstaticto be used as a parameter toqsort.