Question about numbers

Started by
2 comments, last by Lalle 22 years, 12 months ago
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
Advertisement
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
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
Thx for all repies guys!
Now my score system will finally work.

Lalle

This topic is closed to new replies.

Advertisement