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: 19513
Posted: Fri Jan 01, 2021 2:53 am
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.
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