You're Browsing As A Guest! Register Now... |
||
|
Become a C++ Expert!
Join 415,729 C++ Programmers for FREE! Get instant access to thousands
of C++ experts, tutorials, code snippets, and more! There are 1,905 people online right now.Registration is fast and FREE... Join Now!
|
||
Page 1 of 1
convert char to int and int to char
#2
Re: convert char to int and int to char
Posted 17 September 2007 - 02:01 AM
tryingcpp, on 17 Sep, 2007 - 02:31 AM, said:
Hi! Please help me to convert a char to int and int to char on Dev C++. I tried with (int)value and int(value) but it doesnt work. Thank you!
if lets say u wanna convert the char a...(int)' a' will return the ascii value of a and (char)97 will return yo a if am not forgetting something
#3
Re: convert char to int and int to char
Posted 17 September 2007 - 03:34 AM
If you are trying to convert the string itself to an int type, you can use the C function, atoi().
If you are converting an int to a string use the C function sprintf
const char * intStr = "10"; int myint = atoi(intStr);
If you are converting an int to a string use the C function sprintf
char Str[16]; int myint = 15; sprintf(Str, "%d", myint);
#7
Re: convert char to int and int to char
Posted 17 September 2007 - 12:19 PM
if you are coverting a character like '9' to an integer then simply think about ascii table.
char c = '5'; int valOfC = (int)(c-'0'); //'5'= 53, '0' = 48, '5' - '0' = 53 - 48 = 5
Page 1 of 1


Ask A New Question
Reply





MultiQuote






|