Hi!
Ok, I honestly have exausted my mind over this one.
I have an array of 12 structures, each one has a name and several other double variables.
I am trying to sort the entries in the structure based on the value of one of those double variables. The one with the largest value ending up at the top.
If anyone has any suggestions for how I could go about it, im not looking for a code reply or 100% but more of a hard shove in the right direction
Currently I have defined a structure called holder to be a temporary place to move a position in the array of structures to.
I have also made an array of 1 of this structure so I can simply refer to it as holder[pos].name, .p etc.
just to explain before the code, .name is a character array[20].
.t is a double. This is the value I want to sort by.
holders is the array of holder structure, my temporary structure.
cars is the main structure I want to sort, cars is an array[12] of car structures.
Code:
int pos = 0;
int i;
for(i=0;i<12;i++)
{
if(cars[i].t>cars[i+1].t)
{
strcpy(holders[pos].name, cars[i].name);
holders[pos].t = cars[i].t;
strcpy(cars[i].name, cars[i+1].name);
carss[i].t = cars[i+1].t;
strcpy(cars[i+1].name, holders[pos].name);
cars[i+1].t = holders[pos].t;
}
}
}
thanks