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

Changing format type.

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



Joined: 12 Dec 2010
Posts: 6
Location: Turkey

View user's profile Send private message AIM Address

Changing format type.
PostPosted: Mon Dec 20, 2010 2:43 pm     Reply with quote

Hello again me and again a problem Very Happy
I'm using a graphic lcd and keypad.
I want to show the button which is pushed.
There is
Code:
key=read_keypad();

and keypad program is coming as int.
But as you know we have to show as char.
How can I convert them?
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Mon Dec 20, 2010 4:59 pm     Reply with quote

Let's say your int (we'll call it 'result') is what you pull in from the keypad.

Since it's a 4x4 keypad (I'm making this up) you've wired up 'result' to equal a range of 0-15

If you want to PRINT 0 to 15, you want to convert that to ascii.

The easiest way is to simply do this:

printf("%u", result);

This will print result (which is an unsigned int) anywhere from 0-15.

If you want padded preceding 0's,
printf("%02u", result);

This will print 00-15 (because of the 2).

And that's it.

Easy.

PrintF -- it's your friend.
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
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