Standard library functions

  • We will see some standard library functions, which works on characters.
  • This Functions operates on characters
  • For using this functions ,We have to specify the header file #include<ctype.h>
Functions and their description.
#include<ctype.h>
Function Description
isdigit(c) Tells character 'c' is digit or not.
isalpha(c) Tells character 'c' is a alphabet or not
isalnum(c) Tells character 'c' is a alphnumeric or not
isspace(c) Tells character 'c' is a space or not
islower(c) Tells character 'c' is a small letter character or not
isupper(c) Tells character 'c' is a Capital letter or not
ispunct(c) Tells character 'c' is a punctuation symbol or not
tolower(c) Converts the uppercase letter to lowercase letter
toupper(c) Converts the lowercase letter to uppercase letter.
isascii(c) Tells character 'c' is a ascii character or not
isprint(c) Tells character 'c' is a printable on screen or not

Lets make a menu driven program to understand all this above listed functions.

#include<stdio.h>

#include<ctype.h>

void main()
{
    int choice;
    char c;
    printf("enter the character:");
    scanf("%c",&c);
    printf("\nWhat you want to check?");
    printf("\n1:alphabet or Not");
    printf("\n2:digit or Not");
    printf("\n3:Punctuation Symbol or Not");
    printf("\n4 :Capital letter or small letter");

    //taking input from the user.
    printf("\nenter your choice");
    scanf("%d",&choice);


    //switching the choice variable
   
    switch(choice)
    {
    case 1: //if choice is 1 then case will get executed.
       if(isalpha(c) == 1) //if this function return 1 then the character is a alphabet otherwise it's not.
          printf("\n%c is a alphabet.",c);
       else
         printf("\n%c is not an alphabet.",c);

       break;

    case 2://if choice is 2 then case will get executed.
       if(isdigit(c)==1) //if this function return 1 then the character is a digit otherwise it's not.
          printf("\n%c is a digit.",c);
       else
         printf("\n%c is not an digit.",c);
       break;


    case 3://if choice is 3 then case will get executed.
       if(ispunct(c)==1)  //if this function return 1 then the character is a symbol otherwise it's not.
          printf("\n%c is a Punctuation Symbol.",c);
       else
         printf("\n%c is not an Punctuation Symbol.",c);
       break;



    case 4://if choice is 4 then case will get executed.
       if(isupper(c)==1) //if this function return 1 then the character is a uppercase letter otherwise it's lowercase letter.
          printf("\n%c is a uppercase letter.",c);
       if(islower(c)==1)
         printf("\n%c is a lowercase letter.",c);

       break;

    default:
        printf("\nInvalid choice!");
        break;
}

 
}

Output for Each choice:

Ouput1:

enter the character : A

What you want to check?");
1:alphabet or Not
2:digit or Not
3:Punctuation Symbol or Not"
4 :Capital letter or small letter

enter your choice:1

A is a alphabet.

Ouput2:

enter the character:1

What you want to check?");
1:alphabet or Not
2:digit or Not
3:Punctuation Symbol or Not"
4 :Capital letter or small letter

enter your choice:2

1 is a digit.

Ouput3:

enter the character:1

What you want to check?");
1:alphabet or Not
2:digit or Not
3:Punctuation Symbol or Not"
4 :Capital letter or small letter

enter your choice:3

@ is a Punctuation Symbol.

Ouput4:

enter the character: a

What you want to check?");
1:alphabet or Not
2:digit or Not
3:Punctuation Symbol or Not"
4 :Capital letter or small letter

enter your choice:4

a is a lowercase letter.

Ouput5:

enter the character: B

What you want to check?");
1:alphabet or Not
2:digit or Not
3:Punctuation Symbol or Not"
4 :Capital letter or small letter

enter your choice:4

B is a uppercase letter.






Further Concepts: