http://stackoverflow.com/questions/1114741/how-to-convert-int-to-char-c
Are you looking for the char equivalent of a single digit number? For example, converting 5 to '5'? If so then you can do the following, assuming of course the char is 9 or less.
char dig = (char)(((int)'0')+i);
http://stackoverflow.com/questions/5029840/convert-char-to-int-in-c-and-c
Depends on what you want to do:
to read the value as an ascii code, you can write
char a = 'a';
int ia = (int)a;
/* note that the int cast is not necessary -- int ia = a would suffice */
to convert the character '0' -> 0, '1' -> 1, etc, you can write
char a = '4';
int ia = a - '0';
/* check here if ia is bounded by 0 and 9 */
本文介绍了如何在C/C++中将整数转换为字符以及如何将字符转换回整数值。提供了两个具体示例:一是将整数5转换为字符'5'的方法;二是如何将字符'a'转换为其ASCII值或将字符'4'转换为整数4。
8670

被折叠的 条评论
为什么被折叠?



