Thread: Need help with a small program

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    11

    Need help with a small program

    #include <stdio.h>

    main()
    {
    int i;
    char c;

    printf("Enter Char: ");
    scanf("%c", &c);

    printf("You entered %c\n", c);
    printf("The ASCII value of %c is %d", c,c);

    return 0;
    }

    Okay, that was simple enough, but I need something like this as my output.

    printf("The ASCII value of %c is %d and it is a LETTER, DIGIT, or OTHERS", c,c);

    I dont know how to setup the LETTER, DIGIT, or OTHERS parts. I know there are functions such as isdigit, but we cannot use them.

    For example: if I enter A it will say that it is a LETTER or if I enter 5 it will say that it is a DIGIT and if I enter 'tab' then it will say OTHERS.

    Can you guys help me out. I am svery stuck with this.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    if ( c >= 'A' && c <= 'Z' )
    if ( c >= '0' && c <= '9' )

    Etc.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    38
    look at your ASCII table
    pseudo code:

    if( 47 < c < 58)
    {
    it's a DIGIT
    }
    else if( 64 < c < 91)
    {
    it's an uppercase LETTER
    }
    else if( 96 < c < 123)
    {
    it's a lowercase LETTER
    }
    else
    {
    it's some OTHER character
    }

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    11

    Reply

    Hello friends, thank you for your guidance. I will be working on this program in a few.

    Thank you again for helping a beginner out.

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    11

    Reply

    Thank you for the help....it all worked out fine.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Please Help with small program
    By cjohnman in forum C Programming
    Replies: 11
    Last Post: 04-14-2008, 09:59 AM
  2. Program to reverse a number. small error with it..
    By comproghelp in forum C Programming
    Replies: 8
    Last Post: 11-22-2004, 10:52 AM
  3. Help writing small program
    By guitarhead2000 in forum C++ Programming
    Replies: 2
    Last Post: 10-13-2004, 12:42 PM
  4. A little Help with a small program
    By whtpirate in forum C Programming
    Replies: 7
    Last Post: 06-05-2003, 06:15 PM
  5. Very small program...Whats wrong???
    By SmokingMonkey in forum C++ Programming
    Replies: 4
    Last Post: 05-30-2003, 09:09 PM