[chuck-users] Std.atoi broken?
Spencer Salazar
ssalazar at CS.Princeton.EDU
Mon Nov 27 14:11:42 EST 2006
Hi Atte,
Std.atoi comes from the C standard library atoi, which converts a
string of ASCII characters into the represented integer if possible.
So the domain of the function is the of set strings like "1", "200",
"32768", etc., for which the return value would be 1, 200, 32768,
etc. Since "a" doesn't represent an integer (in base ten) it just
returns 0 in that case. Std.itoa, which is available but not
documented, takes an integer like 1, 200, or 32768 and returns "1",
"200", or "32768".
As far as getting the ASCII value of a character in a string, I don't
believe there is a good way of doing that yet. It should be possible
to do once chuck's support of string operations is implemented, and
that is something high on the priority list.
The only way I can think to do this right now in chuck is to build an
associative array, associating each single character string with its
ASCII value by hand.
hope this helps,
spencer
On Nov 27, 2006, at 12:24 PM, Atte André Jensen wrote:
> Hi
>
> I might be doing something wrong, but it seems to me that atoi is
> behaving a bit strange...
>
> <<<Std.atoi("a")>>>;
> <<<Std.atoi("b")>>>;
> <<<Std.atoi("c")>>>;
> <<<Std.atoi("d")>>>;
>
> prints:
>
> 0 :(int)
> 0 :(int)
> 0 :(int)
> 0 :(int)
>
> Am I doing something wrong or are my expectations (97-100) for atoi
> out
> of proportions?
>
> What I'm trying to do is convert from the "a" to 97 as read by
> KBHit->getchar() and back. This also means that I've been looking for
> itoa, which I couldn't find.
>
> --
> peace, love & harmony
> Atte
>
> http://www.atte.dk | quintet: http://www.anagrammer.dk
> | compositions: http://www.atte.dk/
> compositions
>
>
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
More information about the chuck-users
mailing list