Problem with qsort function ordering a struct vector in C

0

Hello, I have a doubt, it turns out that I have problems when ordering a vector of structs based on a variable of type float (within the struct) from highest to lowest, everything works as it should unless the qsort () that is not ordering the struct.

typedef struct {
  char nombre[26];
  char pais[4];
  double punt;
  int cantgen;
  char generos[6][11];
}serie;

int comparafloat(const void* a, const void* b);
void BUSCARPORGENERO(int,serie*);

void BUSCARPORGENERO(int n, serie *vector){
    int i,j;
    int cont=0;
    char genero[11];
    serie aux[20];
    scanf("%[^(\n)]s",genero);
    getchar();
    strupr(genero);
    for (i=0;i!=n;i++){
        for(j=0;j!=vector[i].cantgen;j++){
            if(strcmp(genero,vector[i].generos[j])==0){
               aux[cont]=vector[i];
                   cont++;
            }
        }
    }

//------------------uso del qsort ---------------------

    qsort(aux,cont,sizeof(serie),comparafloat);

//-----------------------------------------------------

    printf("---- SERIES GENERO : %s ----\n",genero);
    for(i=0;i!=cont;i++){
        printf("%25s%6.1f\n",aux[i].nombre,aux[i].punt);
    }

}

// funcion compara que usa el qsort()

int comparafloat(const void* a, const void* b)
{
    const serie arg1= *(const serie*)a;
    const serie arg2= *(const serie*)b;

    if ( (arg1.punt) > (arg2.punt) )
    return -1;
    if ((arg1.punt) < (arg2.punt) )
    return 1;

    return 0;
}

I'll be waiting for the answers, thanks!.

    
asked by Benjamin Felipe Morales Ortiz 21.11.2018 в 14:58
source

0 answers