Click here to Skip to main content
15,892,965 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an array of structures, each of this type

struct A {
char filename[];
off_t filesize;
};

I'm trying to sort this array of structs according to filesize, so that I can , for instance, print the 5 largest file (include filename and its size) from this array of data.


Also I'm trying to avoid manually write up bubble sort or whatever algorithm. So are there any functions from standard c libraries that I can grab?
Posted

1 solution

There is a function in the C standard library called qsort that will do what you want to. All you have to do now is to look into the documentation.

Cheers!
 
Share this answer
 
Comments
H.Brydon 23-Feb-13 23:00pm    
Nicely done. +5 :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900