By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,591 Members | 1,007 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,591 IT Pros & Developers. It's quick & easy.

A query

P: 3
I need a linux C program to convert an integer to ASCII character ?
Feb 25 '08 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 849
Characters and integers are directly comparable and castable to each other. Thus, assuming your int is 0<=x<=127, you can simply cast like so:

Expand|Select|Wrap|Line Numbers
  1. int x;
  2. char c = (char) x;
  3.  
If you want the character representation of a number (like "123" for 123), try looking into sprintf, since itoa isn't standard for some silly reason.
Feb 25 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.