# convert 123 into 1,2 & 3

Hi again

another qu concerns the following:

if i have the 123d and i want to have each element in it's own char
like

int no = 123;

char huns = 123/100; //works!! i have 1 in huns
char tens = This is were am stuck!!
char units = 123 MOD 10; //works!! i have 3 in units.

but how do i get my tens?
this has me stumped.
could u also help with this?

Thanx

• okay i think i've solved this one if i just div the result by 10 then i'll have my 10's.

: char tens = (123%10)/10;

thanx anyway

: Hi again
:
: another qu concerns the following:
:
: if i have the 123d and i want to have each element in it's own char
: like
:
: int no = 123;
:
: char huns = 123/100; //works!! i have 1 in huns
: char tens = This is were am stuck!!
: char units = 123 MOD 10; //works!! i have 3 in units.
:
: but how do i get my tens?
: this has me stumped.
: could u also help with this?
:
: Thanx
:

• [code]
#include

int n=179;
char buf [16];

sprintf (buf, "%d", n);
char c1 = buf [0]; // Will be '1'
char c2 = buf [1]; // Will be '7'
char c3 = buf [2]; // Will be '9'

[/code]
• Hi,
thankx but id like it in dec, i think that this would give me ascii?
am i wrong?

: [code]
: #include
:
: int n=179;
: char buf [16];
:
: sprintf (buf, "%d", n);
: char c1 = buf [0]; // Will be '1'
: char c2 = buf [1]; // Will be '7'
: char c3 = buf [2]; // Will be '9'
:
: [/code]
:

• [b][red]This message was edited by AsmGuru62 at 2002-10-25 6:28:29[/red][/b][hr]
: Hi,
: thankx but id like it in dec, i think that this would give me ascii?
: am i wrong?
:
:
: : [code]
: : #include
: :
: : int n=179;
: : char buf [16];
: :
: : sprintf (buf, "%d", n);
: : int c1 = buf [0][red]-'0'[/red]; // Will be decimal 1
: : int c2 = buf [1][red]-'0'[/red]; // Will be decimal 7
: : int c3 = buf [2][red]-'0'[/red]; // Will be decimal 9
: :
: : [/code]
: :
:
:
[blue]Yes. It will give an ASCII, but with RED - it will be DEC.[/blue]

• Thankx v. Much

: [b][red]This message was edited by AsmGuru62 at 2002-10-25 6:28:29[/red][/b][hr]
: : Hi,
: : thankx but id like it in dec, i think that this would give me ascii?
: : am i wrong?
: :
: :
: : : [code]
: : : #include
: : :
: : : int n=179;
: : : char buf [16];
: : :
: : : sprintf (buf, "%d", n);
: : : int c1 = buf [0][red]-'0'[/red]; // Will be decimal 1
: : : int c2 = buf [1][red]-'0'[/red]; // Will be decimal 7
: : : int c3 = buf [2][red]-'0'[/red]; // Will be decimal 9
: : :
: : : [/code]
: : :
: :
: :
: [blue]Yes. It will give an ASCII, but with RED - it will be DEC.[/blue]
:
:
: