Thread: Convert int to char

  1. #1
    Registered User
    Join Date
    Sep 2005

    Convert int to char


    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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    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.

  3. #3
    Registered User
    Join Date
    Sep 2005
    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
    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, 07:34 AM