In C, how can I convert an int to a char, such as convert the int 5 to the char '5'?
Printable View
In C, how can I convert an int to a char, such as convert the int 5 to the char '5'?
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'
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.