c++ - Convert integer to char array function -
i want convert number not zero-terminated char array without predifined c / c++ function (e.g itoa). don't have much space left (working on embedded application 5kb pgm space total of i'm allready using 4.862kb) , output function doesn't take zero-terminated char arrays; array , length.
edit 1: i'm not working company :p
edit 2: doesn't take means no reason won't send if there's 0-byte within array.
edit 3: solved using modified version of method 'vlad moscow' below. still of you, tried helping me :)
edit 4: if cares: project setting avr based alarm clock using bluetooth.
as hourly rate equal 0 $ (i unemployed) show possible approach.:)
in sentiment simplest way write recursive function. example
#include <iostream> size_t my_itoa( char *s, unsigned int n ) { const unsigned base of operations = 10; unsigned digit = n % base; size_t = 0; if ( n /= base of operations ) += my_itoa( s, n ); s[i++] = digit + '0'; homecoming i; } int main() { unsigned x = 12345; char s[10]; std::cout.write( s, my_itoa( s, x ) ); homecoming 0; }
the output is
12345
though used unsigned int
can modify function take objects of type int.
if need allocate character array in function simpler , can non-recursive.
c++ c arrays char
No comments:
Post a Comment