Jump to content
  • Advertisement
Sign in to follow this  
toXic1337

ASCII to char* conversion?

This topic is 4831 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I'm stupid! I've done the research and can't seem to find anything in C++ that is related to converting an ASCII value into its character counterpart. I know how to do it in VB, but since I'm working on a game in C++/SDL, well... you see where I'm going. Anyway, Thanks in Advance Guys! toXic1337

Share this post


Link to post
Share on other sites
Advertisement
C++ characters are usually stored by ASCII value (skinny literals are, at least).

#include <cassert>

int main () {
char n = 'n';
assert( n == 110 );
n = 110;
assert( n == 'n' );
assert( 110 == 'n' );
}

Share this post


Link to post
Share on other sites
Quote:
Original post by toXic1337
I've done the research and can't seem to find anything in C++ that is related to converting an ASCII value into its character counterpart.
You don't have to! That's the beauty of it.
'7' and 0x37 and 55 are one and the same thing. A character IS an integral type.

Share this post


Link to post
Share on other sites
I'm not quite clear with your question, because ASCII values usually corrispond to characters, so there really doesn't need to be a conversion. i.e. the ASCII value is the character. When you create strings of text, be sure to use the char data type (unless you plan to use unicode which you probably don't want to get into). If you use int or any other data type, string functions can't use them because they are more than 8 bits wide.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!