| Classification Function | Definition |
|---|---|
| isalnum(ch) | This function returns true if the character ch is a letter or a digit. |
| isalpha(ch) | This function returns true if the character ch is a letter. |
| iscntrl(ch) | This function returns true if the character ch is a control character. (Ex: \t, \n, \b, \r) |
| isdigit(ch) | This function returns true if the character ch is a digit. |
| isgraph(ch) | This function returns true if the character ch is not a space but a printable value. |
| islower(ch) | This function returns true if the character ch is a lowercase letter. |
| isupper(ch) | This function returns true if the character ch is an uppercase letter. |
| isprint(ch) | This function returns true if the character ch is a printable character. |
| ispunct(ch) | This function returns true if the character ch is a punctuation character. (Ex: !, #, $, @) |
| isspace(ch) | This function returns true if the character ch is whitespace. |
| isblank(ch) | This function returns true if the character ch is blank. |
| isxdigit(ch) | This function returns true if the character ch is a hexadecimal digit. |
| Transformation Function | Definition |
| tolower(ch) | This function is used to change character ch to lowercase if it is an uppercase letter otherwise leave it unchanged. |
| toupper(ch) | This function is used to change character ch to uppercase if it is a lowercase letter otherwise leave it unchanged. |
/*C++ program to check isalnum() function*/ #include<iostream> #include<cctype> using namespace std; int main(){ char ch[10] = "12Abc@"; //working of isalnum() function for(int i = 0; i < 6; i++){ if(isalnum(ch[i])) cout<<ch[i]<<" is an alphanumeric character."<<endl; else cout<<ch[i]<<" is not an alphanumeric character."<<endl; } return 0; }
1 is an alphanumeric character. 2 is an alphanumeric character. A is an alphanumeric character. b is an alphanumeric character. c is an alphanumeric character. @ is not an alphanumeric character.
/*C++ program to check isalpha() function*/ #include<iostream> #include<cctype> using namespace std; int main(){ char ch[10] = "1Ab@"; //working of isalpha() function for(int i = 0; i < 4; i++){ if(isalpha(ch[i])) cout<<ch[i]<<" is an alphabet character."<<endl; else cout<<ch[i]<<" is not an alphabet character."<<endl; } return 0; }
1 is not an alphabet character. A is an alphabet character. b is an alphabet character. @ is not an alphabet character.
// C++ program to check iscntrl() #include <cctype> #include <iostream> using namespace std; int main(){ char ch[5] = "\nA\t\b"; //working of iscntrl() function for (int i = 0; i < 4; i++) { if (iscntrl(ch[i])) cout<<"Character is a control Character"<<endl; else cout<<"Character is a not control Character"<<endl; } return 0; }
Character is a control Character Character is a not control Character Character is a control Character Character is a control Character
//C++ program to check isdigit() function #include<iostream> #include<cctype> using namespace std; int main(){ char ch[5] = "A123"; //working of isdigit() for(int i = 0; i < 4; i++){ if(isdigit(ch[i])) cout<<ch[i]<<" is a digit."<<endl; else cout<<ch[i]<<" is not a digit."<<endl; } return 0; }
A is not a digit. 1 is a digit. 2 is a digit. 3 is a digit.
//C++ program to check isgraph() function #include<iostream> #include<cctype> using namespace std; int main(){ char ch[5] = "$\tA2"; //working of isgraph() for(int i = 0; i < 4; i++){ if(isgraph(ch[i])) cout<<ch[i]<<" is a graphical character."<<endl; else cout<<ch[i]<<" is not a graphical character."<<endl; } return 0; }
$ is a graphical character. is not a graphical character. A is a graphical character. 2 is a graphical character.
//C++ program to check islower() and isupper() function #include<iostream> #include<cctype> using namespace std; int main(){ char ch[5] = "ABcd"; //working of isupper() and islower() for(int i = 0; i < 4; i++){ if(islower(ch[i])) cout<<ch[i]<<" is a lowercase character"<<endl; if(isupper(ch[i])) cout<<ch[i]<<" is an uppercase character"<<endl; } return 0; }
A is an uppercase character B is an uppercase character c is a lowercase character d is a lowercase character
//C++ program to check isprint() function #include<iostream> #include<cctype> using namespace std; int main(){ char ch[6] = "A\tBc1"; //working of isprint() for(int i = 0; i < 5; i++){ if(isprint(ch[i])) cout<<ch[i]<<" is a printable character"<<endl; else cout<<ch[i]<<" is not a printable character"<<endl; } return 0; }
A is a printable character is not a printable character B is a printable character c is a printable character 1 is a printable character
//C++ program to check ispunct() function #include<iostream> #include<cctype> using namespace std; int main(){ char ch[7] = ")#!\t2'"; //working of ispunct() for(int i = 0; i < 6; i++){ if(ispunct(ch[i])) cout<<ch[i]<<" is a punctuation character"<<endl; else cout<<ch[i]<<" is not a punctuation character"<<endl; } return 0; }
) is a punctuation character # is a punctuation character ! is a punctuation character is not a punctuation character 2 is not a punctuation character
//C++ program to check isspace() function #include<iostream> #include<cctype> using namespace std; int main(){ char ch[7] = "A\n\t#2"; //working of isspace() for(int i = 0; i < 5; i++){ if(isspace(ch[i])) cout<<"Character is a space character"<<endl; else cout<<"Character is not a space character"<<endl; } return 0; }
Character is not a space character Character is a space character Character is a space character Character is not a space character Character is not a space character
//C++ program to check isblank() function #include<iostream> #include<cctype> using namespace std; int main(){ char ch[7] = " \n\t2"; //working of isblank() for(int i = 0; i < 4; i++){ if(isblank(ch[i])) cout<<"Character is a blank character"<<endl; else cout<<"Character is not a blank character"<<endl; } return 0; }
Character is a blank character Character is not a blank character Character is a blank character Character is not a blank character
//C++ program to check isxdigit() function #include<iostream> #include<cctype> using namespace std; int main(){ char ch[7] = "AB120X"; //working of isxdigit() for(int i = 0; i < 6; i++){ if(isxdigit(ch[i])) cout<<ch[i]<<" is a Hexadecimal character"<<endl; else cout<<ch[i]<<" is not a Hexacecima character"<<endl; } return 0; }
A is a Hexadecimal character B is a Hexadecimal character 1 is a Hexadecimal character 2 is a Hexadecimal character 0 is a Hexadecimal character X is not a Hexacecima character
//C++ program to check tolower() and toupper() function #include<iostream> #include<cctype> using namespace std; int main(){ char ch1[11] = "welcome"; char ch2[11] = "ALGOLESSON"; //converting to uppercase for(int i = 0; i < 7; i++){ cout<<(char)toupper(ch1[i]); } cout<<"\t"; //converting to lowercase for(int i = 0; i < 10; i++){ cout<<(char)tolower(ch2[i]); } return 0; }
WELCOME algolesson
.jpg)



Trends is an amazing magazine Blogger theme that is easy to customize and change to fit your needs.