How to convert int to char

I'm going to convert int to char like: 2 -> '2' not 68 -> 'D' but I don't know what to do. Any idea? Thanks.
1
2
3
  int val = 2; 
  char c; 
  c = (char)(val + '0');  // Assumes val is only 0-9 


Not sure what you mean by "not 68 -> 'D' "
OK. Thanks.
I meant (char)68 -> 'D'.
Still don't understand what you're saying about (char)68 -> 'D'
I think OP means that the program should only convert individual digits to char representation, but should not convert numbers like 68 to char which will result in a character like 'D'. In that case, OP should be calling the isdigit function prior to converting

http://www.cplusplus.com/reference/cctype/isdigit/
Topic archived. No new replies allowed.