0

Hello,

I'm working on a problem (Huffman Tree encoding/decoding) and I need to covert and Int to a char.

I was trying to use

char temp = static_cast <char> (index);  //index is an integer

it compiles but if I try to print, it crashes so obviously that idea doesn't work (or at least I am doing it wrong lol)

I know about the itoa function but we are not allowed to use it as it will not work with cygwin.

Thanks

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by jonsca
1

Make sure it's between 0 and 9 and then add '0' to it. char a; a= '0' + 1 (a = '1')

0

Maybe I was being vague, I meant I was trying to do something like saving 100 as a char would in turn be translated to 'd'. But it turns out my idea works I was just being goofy and forgot to place a check to keep it from trying to print a non printable character.

0

ah ok. Yeah, looking back I see what you mean now, the way I read it was you had a single integer digit and were trying to "cast" it to it's character. Apologies then. At least you figured it out.

Edited by jonsca: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.