CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Best way to sort??

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jfk1965



Joined: 21 Oct 2003
Posts: 58

View user's profile Send private message

Best way to sort??
PostPosted: Wed Apr 05, 2006 4:56 am     Reply with quote

Help minds gone blank just can't think this one through at the moment.

I have an array with 10 readings from the 10 ADC pins stored in it, I need to find which one is the lowest value what's the easiest way to do this without endless if statements.

thanks

JFK
sjbaxter



Joined: 26 Jan 2006
Posts: 141
Location: Cheshire, UK

View user's profile Send private message Visit poster's website

PostPosted: Wed Apr 05, 2006 5:18 am     Reply with quote

Try this ...

Code:
int8 lowestValueIndex;
uint16 lowestValue;
lowestValue = 0xFFFF;   // max value for a uint16
lowestValueIndex = -1;
for (i=0; i<10; i++) {
    if (myValues[i] < lowestValue) {
        lowestValue = myValues[i];
        lowestValueIndex = i;
    }
}


lowestValue should use the same variable type as myValues[].

Although you should have been able to figure this one out !!!
_________________
Regards,
Simon.
Ttelmah
Guest







PostPosted: Wed Apr 05, 2006 5:19 am     Reply with quote

Depends how old your compiler is, but if it is recent, look at 'Qsort' in the manual.

Best Wishes
jfk1965



Joined: 21 Oct 2003
Posts: 58

View user's profile Send private message

PostPosted: Wed Apr 05, 2006 7:40 am     Reply with quote

Thanks guys, I now I should have been able to do this but we have builders in our building at the moment and they are cutting a wall with a cutting disk so it's a little difficult to concentrate.

JFK
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group