Thread: Converting words into ASCII values

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    60

    Converting words into ASCII values

    I was just wondering whether it is possible to convert characters into their ASCII values or values in the alphabet easily without needing a load of if statements.

    The only way I can think of doing it is the afformentioned by using an if and 25 else if statements.

    Thanks

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    char a = 'a';
    int x = a;
    printf ("Char %c - ASCII %x", a, x);
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    60
    thanks I thought it would error because of the different data types.

  4. #4
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    C is not exactly built around type-safety. A char is not much more than an 8 bit signed integer.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. using structures to assign unique values to words?
    By coreyt1111 in forum C++ Programming
    Replies: 3
    Last Post: 11-29-2006, 11:19 AM
  2. Converting words to *'s
    By FingerPrint in forum C++ Programming
    Replies: 5
    Last Post: 10-21-2006, 03:40 PM
  3. Replies: 11
    Last Post: 03-24-2006, 11:26 AM
  4. Do arrow keys have two ascii values
    By vaibhav in forum C++ Programming
    Replies: 4
    Last Post: 01-16-2006, 08:03 AM
  5. Problem with malloc() and sorting words from text file
    By goron350 in forum C Programming
    Replies: 11
    Last Post: 11-30-2004, 10:01 AM