int and char conversion
2014-10-01 21:52
295 查看
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.
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
to convert the character
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 */
相关文章推荐
- SqlException with message "Caught java.io.CharConversionException." and ERRORCODE=-4220
- int and string conversion
- 6410_io_drv.c: error: invalid operands to binary << (have 'char *' and 'int') 错误处理
- int to char* and char* to int
- Ordered comparison between pointer and zero ('const char *' and 'int')
- Java: string and int conversion
- char and int
- SqlException with message "Caught java.io.CharConversionException." and ERRORCODE=-4220
- ATL and MFC String Conversion Macros(Cstring转char*)
- Determine the ranges of char , short , int , and long variables
- char and int Convert
- atoi char and string to int
- Qt中QString,char,int,QByteArray之间的转换
- char 转换成int的应用
- char,int,float,double所占字节数
- MFC CString Char* int之间相互转换。
- java.io.CharConversionException: isHexDigit
- 解决“invalid conversion from void* to char*”和“deprecated conversion from string constant to 'char*' "
- char * a, char ** a, char * a[], char a[][], char * a[][], char ** a[][], char * a [][][], and so on
- 不使用库函数,编写函数int strcmp(char *source, char *dest) 相等返回0,不等返回-1;