View Single Post
  #2 (permalink)  
Old 09-24-2007, 11:49 PM
v0id's Avatar   
v0id v0id is online now
Super Moderator
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,415
Last Blog:
CherryPy(thon)
Rep Power: 27
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

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.
Reply With Quote