C++ ctype.h Library Function
All inbuilt function
which are declared in ctype.h header file are there and they are
1.
isalnum()
2.
isalpha()
3.
isdigit()
4.
islower()
5.
isuper()
Now will define the
ctype function.
Fig: C++ ctype.h Library Function |
1.
isalnum()
check whether character
is alphanumeric.
Program:
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
void main()
{
int ch;
cout<<“Input
string”;
if(isalum(ch))
cout<<“the int”;
else
cout<<”the
alphabet”;
getch();
}
Output:
Input string
a
the alphabet
2.isalpha()
Check whether character
is alphabetic.
Program:
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
void main()
{
char dwivedi;
cout<<“Input
string”;
cin>>dwivedi;
if(isalph(dwivedi))
cout<<”the
character is alphabet”;
else
cout<<”the
alphabet is not a character ”;
getch();
}
Output:
Input string
Dwivedi
The character is
alphhbet
3.isdigit()
Check whether character
is digit.
Program:
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
void main()
{
char ch;
cout<<“Input
value”;
cin>>ch;
if(isdigit(ch))
cout<<“the alphabet is digit”;
else
cout<<“the
alphabet is not a digit”;
getch();
}
Output:
Input value
Ram
The alphabet is not a
digit
4.islower()
Convert to lowercase.
Program:
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
void main()
{
char ch;
cout<<“Input
value”;
cin>>ch;
if(islower(ch))
cout<<“the alphabet is lower case”;
else
cout<<“the char
is not in lower case”;
getch();
}
Output:
Input value
Ram
The alphabet is lower case
5.isupper()
Covert into upper case.
Program:
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
void main()
{
char ch;
cout<<“Input
value”;
cin>>ch;
if(isupper(ch))
cout<<“the char is upper case”;
else
cout<<“the char
is not uppercase”;
getch();
}
Output:
Input value
RAM
The char is upper case
No comments:
Post a Comment