how to transform integer to char ?
int x=3;
char y;
i know that in order to do the opposite thing
i need to
Code:int x; char y='3'; x=y-'0';
This is a discussion on how to transform integer to char.. within the C Programming forums, part of the General Programming Boards category; how to transform integer to char ? int x=3; char y; i know that in order to do the opposite ...
how to transform integer to char ?
int x=3;
char y;
i know that in order to do the opposite thing
i need to
Code:int x; char y='3'; x=y-'0';
a 'char' is an unsigned /or/ signed integer of at least 8 bits,
an 'int' is a signed integer of at least 16 bits (to be checked) so you can cast from one to the other with the expected loss from int to char...
Well, if the opposite is to subtract, then perhaps what you should do is to add. Of course, the assumption is that the integer is only one digit.
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
i can do casting??
Code:int x=3; char y; y=(char)x;
Yes, e.g.,
You might want to assert(x >= 0 && x <= 9) since this is only supposed to work with x being in that range.Code:int x = 3; char y; y = (char)(x + '0');
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
Yes, casts work for all elementary types (with possible side effects).i can do casting??
C-compiler Design Rules*:
rule 1: you do not prevent the programmer from doing what [s]he wants
rule 2: you DO NOT prevent the programmer from doing what [s]he wants
*c99 rationale, introduction, 'Keep the spirit of C'
Last edited by root4; 12-31-2008 at 09:59 AM.
Maybe you should take a look at the itoa and atoi functions![]()
atoi does not apply here and itoa is non-standard (but then there's the printf-family of functions).Originally Posted by KroniskBakfylla
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way