Convert int to char

This is a discussion on Convert int to char within the C++ Programming forums, part of the General Programming Boards category; Hello! How can I convert an integer to it's associated character? For instance the value "27" stands for the "ESC-Key", ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    19

    Convert int to char

    Hello!

    How can I convert an integer to it's associated character?
    For instance the value "27" stands for the "ESC-Key", "97" stand for "a" and so on.

    Thank you,

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    Chars are just small integers, so
    ch = 'a';
    ch = 97; // assuming ASCII
    are the same thing.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    19
    ok. but I am not completely sure how to use it.

    I want to do a sort of key-mapping. Therefore on the one hand I get the key as a const char* which I want to convert to the associated ASCII number.
    But I also want to do this in the other direction so that I get a char* representation of the ASCII code.

    [EDIT]: I got it .

    Another question: how can I convert a char* to a ASCII code?
    (e.g. "a" => 97).
    Last edited by pixsta; 04-14-2006 at 02:27 AM.

  4. #4
    Registered User
    Join Date
    Sep 2005
    Posts
    19
    Thank you. I finally got all working.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. can some one please tell me the cause of the error ?
    By broli86 in forum C Programming
    Replies: 8
    Last Post: 06-26-2008, 08:36 PM
  3. Replies: 8
    Last Post: 03-10-2008, 11:57 AM
  4. How do i un-SHA1 hash something..
    By willc0de4food in forum C Programming
    Replies: 4
    Last Post: 09-14-2005, 05:59 AM
  5. easy if you know how to use functions...
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 01-31-2002, 06:34 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21