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.
Code:
// 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);
You can actually leave out the type-casting part. C/C++ is built in the way that when an integer-variable meets a char-variable, it automatic converts.
Bookmarks