How to check whether a character is an alphabet or not in C program



To do this get the character as input from a  variable and check the condition whether it is greater or equal from 'a' to 'z' and 'A' to 'Z'.
Let's see a scenario where we can use it.

Twin glitter doors are a type of bus door systems. This kind of door system for buses is suitable for city-bus entrance and exit doorways. In many of the buses, the door is automatically locked when no one gets into the bus. HIGHLIGHT automobile is the best manufacturer for such type of doors. To survive in the market they must implement some locking and unlocking mechanism.

So they have decided to change the mechanism for unlocking the door. They allow the passenger to unlock the door by pressing any alphabets in the virtual keyboard. The door will unlock if and only if the passenger presses any alphabet.

Write a C program to implement the above scenario.


Test Case

Input 1

A

Output 1

Welcome! Happy Journey.


Input 2

5

Output 2

Sorry! You have pressed an invalid key.




Input 3

-2

Output 2

Sorry! You have pressed an invalid key.


C Program:

#include<stdio.h>
int main()
{
    char c;
    scanf("%c",&c);
    if((c>='a' && c<='z') || (c>='A' && c<='Z'))
    {
        printf("Welcome! Happy Journey.");
    }
    else
    {
        printf("Sorry! You have pressed an invalid key.");
    }
    return 0;
}


Happy Coding!!!!







Comments

Popular posts from this blog

Artificial Intelligence

The taxonomy of CASE Tools

Zoho Second round - adding a digit to all the digits of a number