Click here to Skip to main content
12,398,000 members (45,855 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C++ C
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 23-Feb-13 12:32pm

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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!
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 23 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100