Categorize a single character that is entered at the terminal. - C Data Type

C examples for Data Type:char

Description

Categorize a single character that is entered at the terminal.

Demo Code

#include <stdio.h>

int main (void)
{
    char c;//  w ww.j  av a  2s.  c  o m

    printf ("Enter a single character:\n");
    scanf ("%c", &c);

    if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
        printf ("It's an alphabetic character.\n");
    else if (c >= '0' && c <= '9')
        printf ("It's a digit.\n");
    else
        printf ("It's a special character.\n");

    return 0;
}

Result


Related Tutorials