qsort
lets you specify your own compare function to specify on what criteria the array should be sorted. It lets you sort an array of any type (can be int
, can be struct
) as long as you know the size of the objects you're sorting. Your best bet will be to create a struct pair { int numValue; char charValue }
to represent the pair. You can
- write a function to accept
numFields
andcharFields
and return an array ofpair
. - write a compare function, using this question and answers for reference. Other code examples here.
- call
qsort
on your array of pairs and your comparison function - write a function to transform the array of
pair
s back tocharFields
.