Archived

This topic is now archived and is closed to further replies.

jasonf

i just can't believe i don't remember this....

Recommended Posts

jasonf    122
too much time spent on 3d maths and not enough on simple c i guess ;( anyway guys, heres the problem.... i''ve got an integer (65) that i have to store as a string as an ascii character, in this case, an A. 66 would be B etc... I thought itoa would work, but that just gave me "65" not "A". is there an itos? if so, i don''t seem to have it, or can''t find a reference for it... please help me with this o so lame question... thanks in advance...

Share this post


Link to post
Share on other sites
ragonastick    134
I''ve never coded in C before, but I''m pretty sure you just need to do some type-casting:

(char) 65

I *think* . I always get excited when it looks like a c question that I might be able to answer, so if this is wrong, then... oh well . If I had a compiler I would check for you now.

Share this post


Link to post
Share on other sites
Peon    276
Dunno if that would work, but that''s what I''d guess too. Also, I think creating a variable of type char and assigning the number to it would work too. The type cast is probably a better method though, assuming it works.

Share this post


Link to post
Share on other sites
Ketzer    122
char in c (inherently unsigned) is nothing but a number from 0 to 255 ... only when printed it is interpreted as a character.
just remember to end your string with a zero byte (if youre actually going to use it with string functions).

cheers

Share this post


Link to post
Share on other sites
jasonf    122
Thanks..

Got it. I have a nice little one line doskey style console working in my app. Took me most of yesterday but whatever...

I just gotta say that this forum rocks!

:j

Share this post


Link to post
Share on other sites