Search Here

C program to check a given character is alphabet or digit or space or something else



/* C program to check whether a given character is an alphabet,a digit,a space character or a special symbol */

void main()
{
    char ch;
    
    printf("Enter a character: ");
    ch=getchar();
    if(isalpha(ch))
    {
        printf("\n%c is an alphabet",ch);
        if(isupper(ch))
            printf("\n%c is in upper case",ch);
        else
            printf("\n%c is in lower case",ch);
    }
    else if(isdigit(ch))
        printf("\n%c is a digit",ch);
    else if(isspace(ch))
        printf("\n%c is a space character",ch);
    else if(ispunct(ch))
        printf("\n%c is a punctuation",ch);
    else
        printf("\n%c is a special symbol",ch);
}

Output

No comments:

Post a Comment