What you want is called a multi-key sort, where anytime the first keys are equal, then the sorting decision rests with the order of the second key. qsort() does this rather easily by modifying the...