How do I use qsort() to sort the array elements of each struct instance in a struct array?

80 Views Asked by At

My objective is to use qsort() to order the 70 element pairs of each of the 9 struct instances using the "rank" column.
I created a compare function although I know this will sort the set of 9 and not the elements within each instance. Do I need to apply qsort() on each of the 9 structs separetely?

#include <stdio.h>
#include <stdlib.h>

typedef struct {
    float rank[70];
    char order[70];
    }nq;

int compF(const void * a, const void * b) {
    
    nq *orderA = (nq *)a;
    nq *orderB = (nq *)b;
    
    return(orderB->rank - orderA->rank);

}

int main(int argc, char *argv[])
{
    nq arr[9];

    // code populates the 70 values of each array within the 9 element struc array 
    
    qsort(arr,9,sizeof(nq),compF);  // this is wrong
    
    return 0;       
}
0

There are 0 best solutions below