This program is to check whether the Entered character is alphabet, hexadecimal, Control character or alphanumeric using function.
Program Code:
/* This program is to check whether the Entered character is alphabet, hexadecimal, Control character or alphanumeric using function in C. */
#include <stdio.h>
//this function will check alphabets or not
void alpha( char ch )
{
if ( ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 )
printf("You Entered is an Alphabet!\n");
else
printf ("You Entered is Not an Alphabet!\n");
}
//this function will check hexadecimal or not
void hexa( char ch )
{
if ( ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'f' || ch >= 'A' && ch <= 'F' )
printf("You Entered is an Hexadecimal Number!\n");
else
printf ("You Entered is Not a Hexadecimal Number!\n");
}
// this function will check control character or not
void control( char ch )
{
if ( ch >= 0 && ch <= 32 )
printf("You Entered is a Control Character!\n");
else
printf ("You Entered is Not a Control Character!\n");
}
//to check alphanumeric or not
void alphanumeric( char ch )
{
if ( ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 || ch >= '0' && ch <= '9' )
printf("You Entered an Alphanumeric Number!\n");
else
printf ("You Entered is Not an Alphanumeric Number!\n");
}
//main function
int main()
{
// declaration of variable
int choice;
char num1, num2, num3, num4;
//this is to run the program again
while (1)
{
//choose what you want to check
printf ("1. Alphabet\n2. Hexadecimal\n3. Control Character\n4. Alphanumeric\n");
printf ("Enter your Choice : ");
scanf ("%d", &choice);
switch (choice)
{
case 1:
//asking to enter an alphabate
printf ("Enter an Alphabet : ");
getchar();
scanf ("%c", &num1);
//function call
alpha( num1 );
break;
case 2:
//asking user to enter an no
printf ("Enter an Hexadecimal Number : ");
getchar();
scanf ("%c", &num2);
//calling the hexa function
hexa (num2);
break;
case 3:
//asking the user to enter an no
printf ("Enter an Control Character : ");
getchar();
getchar();
getchar();
getchar();
scanf ("%c", &num3);
//calling the function
control (num3);
break;
case 4:
printf ("Enter an Alpha Numeric Character : ");
getchar();
scanf ("%c", &num4);
getchar();
//calling the function
alphanumeric (num4);
break;
default:
printf("Invalid Entry!\n");
break;
}
//this loop is to run the program again
char yes;
printf("\nTo Continue ['Y'/'n'] : ");
getchar();
yes=getchar();
if (!( yes == 'y' || yes == 'Y' ))
{
break;
}
}
return 0;
}
Program Output:
Post a Comment