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

char TO int convert

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



Joined: 08 Sep 2020
Posts: 220

View user's profile Send private message

char TO int convert
PostPosted: Fri Jan 01, 2021 2:27 am     Reply with quote

Merry christmas everyone.
I want to ask you something. How do I convert a variable that is char to an int variable ? I'm doing a keypad reading. How do I convert character information to int ? Does CCS C have source code for this?

For example
Code:

         int32 gecici_value;
         char value;

         value = kbd_getc();
         gecici_value = (int32)value;
         printf(lcd_putc, "%ld",gecici_value);

_________________
Best Regards...
MCUprogrammer
_______________________________
Work Hard
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Fri Jan 01, 2021 2:53 am     Reply with quote

There is little point in converting to an int32. You only have a single character.
Characters from a keyboard driver are normally in 'ASCII', so the number
1 is actually sent to you as the ASCII character '1' (0x31). To be worth
converting to int32, you would need to assemble a test 'string' of successive
characters, terminate with a '\0' when the enter is pushed, and use
atol on this string to get the whole numeric value being input.
To display the single character' the printf formatter %c will display it
as it is.
To convert a single character, just subtract 0x30 from it.
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