Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Can you crack this nut.......?????

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

Im making a numberlibrary...I send in a ínteger and it is displayed with my own number font. But I have a problem. I want to take out all numbers from an integer and put them in a vector. Example: Integer value: 1265 Vector value: v[0]= 1 v[1]= 2 v[2]= 6 v[3]= 5 It doesn''t matter if it is a integer vector or a char vector. Can anybody help me?????

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
Use _itoa(), or a similiar integer to string conversion routine, and then parse the string manually.

char s_number[10]; //enough space for any 32-bit int
int number = 12345678, x;
vector numstring;

_itoa(number, s_number, 10);

for(x=0; x<10; x++)
if(s_number[x] == ('' '' // ''\0'')) break;
else numstring.push_back(s_number[x]);

You should check for spaces or null terminators because numbers dont have them. And depending on the implementation of _itoa() you may or may not have a null terminator in the string at the end of the number. This code should work with any compiler, except for the _itoa(), which is Microsoft''s implementation.

Cauldron the Ancient

Share this post

Link to post
Share on other sites
Yep, strategicalliance has the idea..

If x is the number ( eg 1234 ),
x%10 = least significant digit (4).
((x - (x%10))/10)%10 = second-least significant digit (3)
((x - ((x - (x%10))/10)%10 )/100)%10 = 2.

Give me one more medicated peaceful moment..
~ (V)^|) |<é!t|-| ~

Share this post

Link to post
Share on other sites

  • 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!