I am trying to sort an array of characters in C but it prints out the same array instead of the sorted
char*P[5] = {"1c", "4h", "3g", "10g"};
total_items = 4; // number of elements in the array.
for(int q =1; q<total_items; q++)
{
for(int k=0; k<total_items-q; k++)
{
if((int)P[k]>=(int)P[k+1])
{
temp=P[k];
P[k]=P[k+1];
P[k+1]=temp;
}
}
}
When I print out the array, it's the same as the original. I tried debugging by printing in the if statements; it turns out it never enters the swap block of the code. Is there something I am missing?
The expected output should be 1c, 3g, 10g, 4h.
strcmpinstead of>=(>).