I'm trying to convert integers to char. Is there anyway to do this. I'm coding a game and am using rand to generate a range of numbers. After 10 these numbers have to be represented by letters. Thanks for your help.
I'm trying to convert integers to char. Is there anyway to do this. I'm coding a game and am using rand to generate a range of numbers. After 10 these numbers have to be represented by letters. Thanks for your help.
Yes. Presumably you are converting the integers 0-9 to the characters '0' - '9' and want 10, for example to become 'A'? If so you can use the fact that characters are actually stored as integer codes so...
... will give A for 10, B for 11, C for 12 ... up to Z for 36. Beyond 36, you will get some other characters depending on the character set of you machine.Code:char x; int i; i = 10; x = (char) i + ('A' - 10);
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.
you could use itoa,ltoa etc functions in stdlib.h
-
>>> use itoa,ltoa
You have to be a bit careful here. Without knowing really what he is doing, (he didn't post his code!!!). itoa converts to a null terminated string, not a single character.
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.
uhh... sorry
-
>>> uhh... sorry
Not necessary! That may well be what he wants, but without knowing what he is doing with his digits and letters, it is impossible to be sure!
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.