Thread: number to a character

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    5

    Thumbs up number to a character

    how do I enter a number and return the numer that represents ASCII value.

    Such as
    "Please enter a number less than 255
    65
    The character that represents ASCII value 65 is A"

  2. #2
    Unregistered
    Guest
    int x;
    scanf( "%d", &x );
    printf("%d is %c.", x, (char)x );

    You don't acutally _have to_ cast it to a char there either...

    Quzah.

  3. #3
    Unregistered
    Guest
    declare a char type variable to print out the ASCII value. Then use the char the same way you would use an int.

    Code:
    #include <stdio.h>
    
    int main(){
      char c;
    
      printf("Please enter a number from 0 to 256");
      scanf("%c", &c);
      printf("The ASCII value is %c", c);
    
      return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with this compiler error
    By Evangeline in forum C Programming
    Replies: 7
    Last Post: 04-05-2008, 09:27 AM
  2. Stone Age Rumble
    By KONI in forum Contests Board
    Replies: 30
    Last Post: 04-02-2007, 09:53 PM
  3. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  4. about wide character and multiple byte character
    By George2 in forum C Programming
    Replies: 3
    Last Post: 05-22-2006, 08:11 PM
  5. If else works but I can't do it with switch
    By g1bber in forum C++ Programming
    Replies: 1
    Last Post: 04-19-2006, 07:02 PM