# Thread: Int to Char

1. ## Int to Char

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.

2. 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...
Code:
```char x;
int i;

i = 10;
x = (char) i + ('A' - 10);```
... 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.

3. you could use itoa,ltoa etc functions in stdlib.h

4. >>> 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.

5. uhh... sorry

6. >>> 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!

Popular pages Recent additions