Thread: Please help with ASCII

  1. #1
    Registered User
    Join Date
    Nov 2001

    Unhappy Please help with ASCII

    Is there a function to convert a character to its ASCII equivalent and assign it to a variable? or is there some other method..??

    I know I can assign a character to an integer variable and get its ascii, but I can't do it with an input of a character variable.

    Please help if you can.

  2. #2
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    I never heard about such a function, but this should do the trick:
    int num1;
    char num2='a';
    num1 = num2;
    now num1 holds the value: 97

    also, read about printf(), %d, %c and how to use them!!!
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe - Developing free software for the community.

  3. #3
    You *might* try the function called atoi()...

    But realistically, it's already a value. if you create a 'char' variable, and it the letter 'g' is input into it (or assigned by you, for that matter), your computer does _not_ remember 'g'... it remembers the ASCII value.

    A char is a signed value from 0 to 127 (in ASCII). an unsigned char is a value from 0 to 255 (in ASCII), which is the maximum range an 8-bit value can hold.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Emphasis on *might*. The reason we say you might be able to use it is that atoi() doesn't take a character. It takes a string as an argument.

    That being said, you cannot simply pass it a single character and expect it to work. You'll have to convert it to a string first.

    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Oct 2001
    What Devil Panther replied is called cast!

    You can also turn it around:
    char a=32;
    and the result is the character '"'.

    Last edited by klausi; 12-05-2001 at 04:22 AM.
    When I close my eyes nobody can see me...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ASCII character with ASCII value 0 and 32
    By hitesh_best in forum C Programming
    Replies: 4
    Last Post: 07-24-2007, 09:45 AM
  2. Replies: 11
    Last Post: 03-24-2006, 11:26 AM
  3. Office access in C/C++ NOT VC++!! :)
    By skawky in forum C++ Programming
    Replies: 1
    Last Post: 05-26-2005, 01:43 PM
  4. ascii values for keys
    By acid45 in forum C Programming
    Replies: 2
    Last Post: 05-12-2003, 07:13 AM
  5. Checking ascii values of char input
    By yank in forum C Programming
    Replies: 2
    Last Post: 04-29-2003, 07:49 AM