cannot get a character, I need one line

This is a discussion on cannot get a character, I need one line within the C Programming forums, part of the General Programming Boards category; this is what I need. I need to enter a number and return it as a character. this is what ...

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

    Angry cannot get a character, I need one line

    this is what I need.
    I need to enter a number and return it as a character.
    this is what I have
    #include <stdio.h>

    int main(){
    char a;

    printf("Please enter a number from 0 to 256");
    scanf("%c", &a);
    printf("The ASCII value is %c", a);

    return 0;
    }
    what am i doing wrong

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    you should take the input as an int not a char.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    11

    Arrow I have your answer

    This will do it for you.

    #include <stdio.h>

    void main()
    {
    int i;

    printf("Enter the number : ");
    scanf("%d", &i);
    printf("The ASCII for that number is %c\n", (char) i);
    }


    When this works, please E-Mail me to tell me that you got it.

    dtblunde@it.uts.edu.au
    With my naked eye I saw all the falling rain, coming down on me...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer and Polymorphism help.
    By Skyy in forum C++ Programming
    Replies: 29
    Last Post: 12-18-2008, 09:17 PM
  2. Printing Length of Input and the Limited Input
    By dnguyen1022 in forum C Programming
    Replies: 33
    Last Post: 11-29-2008, 04:13 PM
  3. ASM beginner gets 24 compiler errors on hello world...
    By Desolation in forum Tech Board
    Replies: 12
    Last Post: 06-16-2007, 11:21 PM
  4. SSCANF help
    By mattz in forum C Programming
    Replies: 7
    Last Post: 12-10-2001, 04:53 PM
  5. Validating the contents of a char buffer
    By mattz in forum C Programming
    Replies: 3
    Last Post: 12-09-2001, 06:21 PM

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