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 CCS Technical Support

change from ASCII code to integer

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







change from ASCII code to integer
PostPosted: Wed May 10, 2006 4:32 am     Reply with quote

how can I change a number from ASCII code to integer.
e.g. I want to different function can be chosen by typing 1, 2 or 3 in PC and the PIC read it through RS232. but the problem was:
when I typed '1' and got it through RS232 by getchar(). The '1' is stored as ASCII code 49, but I want to use '1' to classify cases..
so, I have to translate the ASCII code of '1' back to integer 1.

please tell me how. thanks
Ttelmah
Guest







PostPosted: Wed May 10, 2006 4:43 am     Reply with quote

If it is only a single digit, then just use:

VAL=(ASC_CHAR-'0');

For a complete 'string' (multiple characters), look at 'atoi'.

Best Wishes
luckyluke



Joined: 18 Apr 2006
Posts: 45

View user's profile Send private message

PostPosted: Wed May 10, 2006 3:04 pm     Reply with quote

numbers begin from 48 (decimal for 0) to 57 (decimal for 9)
if you sbstract 48 from what you get with getchar() you will have the number
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