Converting Char value to ASCII number, C++
i know there is already a post like this up, and i'v read it but it's not really helping me.
I need to convert a char value into it's ASCII number equivilent.
The letter is an input from the user so it's completly random, and it's just a single letter.
I know how to write the program so that it just outputs the value as a number but what i actually need to do is convert it and then assign that number to a different variable.
I'm assuming there is a particular function i can use, i just don't know what it is!
If worst comes to worst i suposse i could just write an if statment for every letter of the alphabet but i'm hoping there is an easier way XD!
Re: Coverting Char value to ASCII number, C++
It's simple. A character that you're using in your program already have an ASCII-value, but you sees it like a character. If you want to have the value itself, you can simply convert the character to an integer.
// C, with C type-casting char cMyCharacter = 'A'; int iMyAsciiValue = (int)cMyCharacter; // C++, with C++ type-casting char cMyCharacter = 'A'; int iMyAsciiValue = static_cast<int>(cMyCharacter);
|Tags: ascii, char|
|Thread Tools||Search this Thread|
|Similar Threads for: "Converting Char value to ASCII number, C++"|
|Thread||Thread Starter||Forum||Replies||Last Post|
|Converting the floating point number to the hexadecimal on the Microsoft Excel 2010||Aag-Man||Windows Software||5||11-07-2011 10:38 AM|
|Converting a string number into sequence of digits||KAIRU26||Software Development||5||13-03-2010 04:46 PM|
|Converting Char to Int in PHP||GlassFish||Software Development||4||05-03-2010 08:06 PM|
|Converting string to char||Abdullah30||Software Development||3||03-09-2009 11:09 PM|
|How to Create ASCII Art||avvia||Windows Software||3||29-06-2009 11:06 AM|