Jump to content
  • Advertisement
Sign in to follow this  
facemn

Convert from wchar_t to int

This topic is 3544 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

In C, how do I convert from a wchar_t to an int? I'm not all that familiar with C which is part of the problem. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Sorry, I should have been more clear. I want the wchar_t value, which is in this case "51" to literally be the number 51.

Share this post


Link to post
Share on other sites
There are three ways of understanding what you say here.

The first is that you have a wchar_t with a numeric value of 51 (namely, 0x0033) and you want to convert it to an integer. This is what my program does.

The second is that you have a wchar_t which contains two ASCII bytes, the first representing the character '5' and the other representing the character '1' (that is, the value 0x3531 on an appropriately-endian platform). You shouldn't be representing things like that.

The third is that you have an array of wchar_t which contains a null-terminated string equivalent to the literal L"51". In that case, you'll probably use something like swscanf.

Share this post


Link to post
Share on other sites
Assuming you mean a null terminated wchar_t array interpreted as a string, in which case, you could use wtoi() on compilers that support it (it's not a standard function), swscanf(), or convert the wchar_t array to a narrow character array with wcstombs() and then use atoi() on that.

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!