Go Down

Topic: Filtering an Integer array of mixed 'characters' and numbers (Read 807 times) previous topic - next topic

trendski

Hi,

I have an integer array which is a mixture of characters and integer numbers (the numbers and characters could be any value - this is just an example):

Code: [Select]
int Array1[]  = {'s',250,'w',10,500,'p',15 };

I want to separate out the numbers and characters into two arrays. One of characters, and one of the integer numbers to get result:

Code: [Select]
ArrayChars[3] ...contains... {'s','w','p'}
ArrayIntNums[4] ...contains...{250,10,500,15}


The characters are commands and the numbers are data for a command. So for example {'s', 250} means "set speed to 250"

I don't even know if it is possible and I may have to store the numbers and characters in separate arrays. I think one main problem might be that some numbers and characters are interchangeable (eg 's' is also 115 and visa-versa in decimal)

Can anyone point me in the right direction?

Many Thanks

Craig Turner, blog: http://gampageek.blogspot.co.uk/ It helps with my learning if I write things down, esp. for others to follow (constructive comments welcomed to improve)

PaulS

Quote
I don't even know if it is possible

Depends. Are the odd positions in the array always letter equivalents, while the even positions are always numbers?

Quote
I may have to store the numbers and characters in separate arrays.

Makes more sense to me.

Quote
Can anyone point me in the right direction?

Thataway!

CrossRoads

I think the best you could do is call them characters if in a certain range, and numbers otherwise.
www.asciitable.com

0x41 to 0x5A are capital letters
0x61 to 0x7A are lowercase letters
everthing else is a number.
Your call if you want to accept other things as characters.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

trendski

Na migo thisaway!  ;)

Thanks for the input PaulS.

I'll go with separate arrays.

Cheers


Craig Turner, blog: http://gampageek.blogspot.co.uk/ It helps with my learning if I write things down, esp. for others to follow (constructive comments welcomed to improve)

trendski

Thanks CrossRoads that link's really useful - I keep it for future reference. 

It is more sensible to go for separate arrays for chars and data. Then I could use other data types as well.

cheers
Craig Turner, blog: http://gampageek.blogspot.co.uk/ It helps with my learning if I write things down, esp. for others to follow (constructive comments welcomed to improve)

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy