|
-
Sep 26th, 2005, 10:32 PM
#1
Thread Starter
Stuck in the 80s
[Resolved] int to char?
In C, how can I convert an int to a char, such as convert the int 5 to the char '5'?
Last edited by The Hobo; Oct 9th, 2005 at 02:04 PM.
-
Sep 26th, 2005, 11:04 PM
#2
Re: int to char?
The itoa function will convert an integer into a string.
Of course, if you just have one digit like in your example, you could just do something like:
Code:
int i = 5;
char c = '0' + i; // c is '5'
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
-
Sep 27th, 2005, 09:58 AM
#3
Re: int to char?
don't use itoa, it is not a standard C function, on the compilers that support it it may have different behaviour!
The official C way of converting a integer to a string is to use sprintf.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|