Once compiled there will be no trace of the variable names in the code. Put the names in an array of chars in the order that you want. Iterate through that and print the names.
So there will be two arrays char sensors[6][2] = {"A", "B", "C", "D", "E"} and int sensorvalues[6] = {300,100,1,489,6}, but how pair it in Arduino as std:pair is not avalible.
So there will be two arrays char sensors[6][2] = {"A", "B", "C", "D", "E"} and int sensorvalues[6] = {300,100,1,489,6}, but how pair it in Arduino as std:pair is not avalible.
int sortable_indicies[5] = {0, 1, 2, 3, 4}; //before sorting, these just count.
Then, sort the indices using a level of indirection:
if (sensors[sortable_indices[i]] < sensors[sortable_indices[j]] {
swap( sortable_indices[i], sensors[sortable_indices[j] );
// eventually giving you a set of sorted indirect indices:
// sortable_indices[] = {2, 4, 3, 1, 0}
And you can print them in sorted order with something like:
for (byte i=0; i <4; i++) {
printf("Sensor%s = %d\n", sensor_names[sortable_indicies[i], sensors[sortable_indices[i]);
}
I hesitate to point out that "A", "B", etc. are lousy sensor names. But, I got over it.
There is really no need to sort the values, to find the largest one. A single pass through the array will find the largest value and it's position in the array. The name is at the same position in the other array.