Weston Cerny <[EMAIL PROTECTED]> writes:

> Oops i'm double using my variable and not checking my bounds correctly
> for a negative number.
>
> string itoa(int in) {
>   string ret = "";
>   int current = in;
>   int digit = 0;
>
>   while (current != 0 && digit = current % 10)
>   {
>      ret = (char)(digit+ (int)'0') + ret;
>      current /= 10;
>   }
>
>   return ret;
> }

I'm sure this is much closer to what they were looking for.  On the
other hand, strings are not a native datatype, so you're still using
standard libraries.  On many embedded systems, you may not have the
luxury of a standard string class, so you'd be stuck with arrays of
characters.  This makes it a little more tricky, since you now have to
deal with the size of the array, who allocates it, etc.

                --Levi

/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/

Reply via email to