Click here to Skip to main content
12,942,930 members (49,449 online)
Rate this:
Please Sign up or sign in to vote.
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 23-Feb-13 12:32pm

1 solution

Rate this: bad
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.

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
OriginalGriff 4,633
CHill60 2,880
Maciej Los 2,268
Jochen Arndt 1,900
ppolymorphe 1,755

Advertise | Privacy | Mobile
Web02 | 2.8.170518.1 | Last Updated 23 Feb 2013
Copyright © CodeProject, 1999-2017
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