Hello again guys,

I've created a bubblesort function to sort a string in chronological order, it is as follows:

void playerSort(int player, double ppg[])
{
    int i,j;
    char a[999][15];
    char temp[15];


/* Converting LF into String */

for(i=0;i<player;i++)
{
  sprintf(a[i],"%.2f",ppg[i]);

}

    /* Sorting Array */

    for(i=1;i<player;i++)
        for(j=0;j<player-i;j++)
        {
            if(strcmp(a[j+1],a[j])<0)
            {
                strcpy(temp,a[j]);
                strcpy(a[j],a[j+1]);
                strcpy(a[j+1],temp);
            }
        }
}

when this sorting function is called in my main function, nothing happens at all. The strings are not sorted. It's like the program isnt even calling the function at all.

/* Calling of sort function */
            playerSort(j,ppg);


            /* Printing sorted list by PPG */
            for(i=1;i<j;i++)
            {
            printf("%2d %5s, %5s \t %s\t%s\t%s  %s  %s  %3s  %3.2lf\n",index[i],lastname[i],firstname[i],team[i],pos[i],games[i],goals[i],assists[i],points[i],ppg[i]);
            }

I'm not sure what's going wrong.

thanks for the help in advance.

That's because you sorted the array defined in your function (a). When the function returns, that array is gone.

What are you trying to accomplish? All this seems to be doing, assuming you get it to work, is sort the ppg of all the players, assigning the lowest ppg to the first player and the highest to the last player. They would no longer have any bearing on the players that originally had the value.

As of right now, I'm simply just trying to sort PPG and return it to main. Then print the sorted array in main with the highest PPG first, and lowest last.

I have an idea of how im going to index the ppg to the players so that the values corrorspond to the actual player but first I want to make sure the bubblesort actually works.

How do I return that sorted function to main? I've had a feeling for a while that I'm missing some serious step somewhere.

As of right now, I'm simply just trying to sort PPG and return it to main. Then print the sorted array in main with the highest PPG first, and lowest last.

Then sort ppg. Don't waste your time
1- converting the ppg values into strings,
2- loading a bogus array, and
3- sort that array.

That should take care of your entire problem -- as posted.

Then sort ppg. Don't waste your time
1- converting the ppg values into strings,
2- loading a bogus array, and
3- sort that array.

That should take care of your entire problem -- as posted.

Agree with you WaltP as converting the ppg values into strings is waste of time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.