Archived

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

Lalle

Question about numbers

Recommended Posts

Is it possible to find out what numbers a variable holds? ie. int var = 683; is it now possible to get the first(6), second(8) and third(3) number to three new variables? Lalle

Share this post


Link to post
Share on other sites
a hack off the top of my head:

int var = 683;
char str_var[64] = "";

sprintf(str_var, "%d", var);

now just get them out of the array...

str_var[0] etc...

-Mezz

Share this post


Link to post
Share on other sites
Or if that doesn''t work, you can try this:

int var = 683;
int var_hundreds, var_tens, var_ones;
int remainder;

var_hundreds = var/100; // var_hundreds is now equal to 6, the number in the hundreds position.
remainder = var%100;
var_tens = remainder/10;
remainder = var_tens%10;
var_ones = remainder;


That should work if the other doesn''t.



"We are the music makers, and we are the dreamers of the dreams."
- Willy Wonka

Share this post


Link to post
Share on other sites