Single character inbuilt Functions 2

7. isprint() :

This function helps us to check whether a specified character is a printable character or not.
Characters like ‘\t’, ‘\n’ etc are not printable character
Rest characters are printable

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

8. ispunct() :

This function helps us to check whether the specified character is a punctuation character or not.
example:
The function returns nonzero/false if char is any of:
! ” # % & ‘ ( ) ; < = >> ?
[ \ ] * + , – . / : ^ _ { | } ~

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

9. isspace() :

This function helps us to check whether character is a space, tab, carriage return, new line, vertical tab or formfeed or not.

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

10. isxdigit() :

This function helps us to check whether the character is a hexadecimal digit (0 to 9, a to f, A to F) or not.

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

11. tolower() :

This function helps to convert an upper case alphabet to its lower form.

#include<stdio.h>
 #include<conio.h>
 #include<ctype.h>
 void main()
 {
   char ch;
   clrscr();    
   printf("Enter any character ");
   scanf("%c",&ch);
   if(isupper(ch))
     printf("Lower form is %c",tolower(ch));
   else
     printf("character is not an upper case alphabet");
 getch();
 }

12. toupper() :

This function helps us to convert a lower case alphabet to its upper form.

#include<stdio.h>
 #include<conio.h>
 #include<ctype.h>
 void main()
 {
   char ch;
   clrscr();    
   printf("Enter any character ");
   scanf("%c",&ch);
   if(islower(ch))
     printf("Upper form is %c",toupper(ch));
   else
     printf("character is not a lower case alphabet");
 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