Character Inbuilt Functions

Single character Functions

header file :ctype.h

1. isalpha() :

This function helps us to check whether a specified character is an alphabet or not.  (a to z or A to Z) 

return value: the function returns nonzero if character is an alphabet otherwise this will return  zero which will be equivalent to false.

 #include <stdio.h>
 #include<ctype.h>
int main()
{
   char ch;
   printf("Enter any character ");
   scanf("%c",&ch);
   if(isalpha(ch))
   printf("it is an alphabet");
   else
   printf("it is not an alphabet");
    return 0;
}

Output:

Enter any character d
it is an alphabet

Enter any character 5
it is not an alphabet

2. islower() :

This function helps us to check whether a specified character is a lower case letter (a to z) or not.

#include <stdio.h>
 #include<ctype.h>
int main()
{
   char ch;
   printf("Enter any character ");
   scanf("%c",&ch);
    if(islower(ch))
   printf("it is a lower case alphabet");
   else
   printf("it is not a lower case alphabet");
    return 0;
}

Output:

Enter any character d
it is a lower case alphabet

Enter any character E
it is not a lower case alphabet

3. isupper() :

This function helps us to check whether the specifiedcharacter is an uppercase letter (A to Z ) or not.

#include <stdio.h>
 #include<ctype.h>
int main()
{
   char ch;
   printf("Enter any character ");
   scanf("%c",&ch);
   if(isupper(ch))
   printf("it is an upper case alphabet");
   else
   printf("it is not an upper case alphabet");
    return 0;
}

Output:

Enter any character D
it is an upper case alphabet

Enter any character w
it is not an upper case alphabet

4. isdigit() :

This function help us to check whether character is a digit (0 to 9) or not

#include <stdio.h>
 #include<ctype.h>
int main()
{
   char ch;
   printf("Enter any character ");
   scanf("%c",&ch);
   if(isdigit(ch))
   printf("it is a digit");
   else
   printf("it is not a digit");
    return 0;
}

Output:

Enter any character 5
it is a digit

Enter any character d
it is not a digit

5. isalnum():

This function helps us to check whether the specificed character is an alphanumeric or not.

#include<stdio.h>
 #include<conio.h>
 #include<ctype.h>
 void main()
 {
   char ch;
   clrscr();
   printf("Enter any character ");
   scanf("%c",&ch);
   if(isalnum(ch))
   printf("it is an alpha numeric character");
   else
   printf("it is not an alpha numeric character");
   getch();
 }

6. isgraph() :

This function helps us to check whether the specified character is a graphics character or not.
for example :
* ‘\n’ ‘\t’ ‘\b’ etc are not graph character.
* a b c are all graph character  

#include<stdio.h>
 #include<conio.h>
 #include<ctype.h>
 void main()
 {
   //char ch='a';
   char ch='\t';
   clrscr();
   if(isgraph(ch))
   printf("it is a graphical character");
   else
   printf("it is not a graphical character");
   getch();
 }

C Language Programming Tutorial

C Language Tutorial Home     Introduction to C Language     Tokens     If Condition      goto statement and Labelname     Switch Statements     For loop     While Loop     Do while loop     break and continue     Functions     Recursion     Inbuild Functions     Storage Classes     Preprocessor     Arrays     Pointers     Structures and Unions     File Handling     Projects

Number Of Visitors

0238284