Hi,
how can I put every digit from a number in an array, like in:
int number=5678;
char numbarr[]={5,6,7,8};
Thank you.
Paco
Hi,
how can I put every digit from a number in an array, like in:
int number=5678;
char numbarr[]={5,6,7,8};
Thank you.
Paco
itoa() converts an integer to a string.
char foo[5];
int bar = 12345;
itoa(bar, foo, 10);
// foo[0] eq '1'
!c
In that example I think you meant:
char foo[5];
int bar = 1234;
converting 12345 to a string would need an array one char bigger, to hold the terminating null
You're correct (a note for the OP: strings are null-terminated), I should've said char foo[6].
!c
paco asked for {5,6,7,8} not {'5','6','7','8'}. I expect we're all thinking ahead to what paco really wants, but I thought I'd repeat the question posed.
paco asked for {5,6,7,8} not {'5','6','7','8'}. I expect we're all thinking ahead to what paco really wants, but I thought I'd repeat the question posed.
Paco probably confused me by using char[] vs int[] or byte[].
Perhaps Paco can clarify by stating whether he wants an array of integers or a character-by-character representation of his number (as a string). =)
If one were to answer for the first, and not the second - how might you accomplish that? I can think of two ways, both of which might qualify as "unnatural acts" and one of which I'm fairly certain might be wrong in the end.
!c
paco asked for {5,6,7,8} not {'5','6','7','8'}. I expect we're all thinking ahead to what paco really wants, but I thought I'd repeat the question posed.
char numbarr[4] was the example output array, but something along these lines would create an integer array of the digits.
int number=5678;
int numbarr[4]; // in the first post, this was an array of chars
char numberStr[5];
itoa(number, numberStr, 10);
for(int i=0 i < 4; i++)
numbarr = (int)numberStr*;[/font]*
_*anyway, I think paco wanted code to display time digits as per this thread: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1234195010/2#2.*_