- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Isupper() and Islower() and their application in C++
The functions isupper() and islower() in C++ are inbuilt functions present in “ctype.h” header file. It checks whether the given character or string is in uppercase or lowercase.
What is isupper()?
This function is used to check whether the given string contains any uppercase letter or not and also if we have one character as an input then it checks whether the character is in uppercase or not.
Syntax
int isupper ( int arg)
Explanation
This function has return type as int as it returns non zero value when the string contains uppercase letter and 0 otherwise. It has one parameter which will contain the character to be checked.
Example
Input − string s = “HELLo”
Output − It contains uppercase letter
Input − string s = “hello”
Output − It doesn’t contains uppercase letter
The function given below will check the string whether it contains uppercase letter or not and if it contains uppercase letter then it will convert them to a lowercase.
Example
#include <stdio.h> #include <ctype.h> int main (){ int i=0; char str[]="Test String.\n"; char c; while (str[i]){ c=str[i]; if (isupper(c)) c=tolower(c); putchar (c); i++; } return 0; }
Output
If we run the above code it will generate the following output −
test string.
What is islower()?
This function is used to check whether the given string contains any lowercase letter or not and also if we have one character as an input then it checks whether the character is in lowercase or not.
Syntax
int islower( int arg)
Explanation
This function has return type as int as it returns non zero value when the string contains lowercase letter and 0 otherwise. It has one parameter which will contain the character to be checked.
Example
Input − string s = “HELLo”
Output − It contains lowercase letter
Input − string s = “hello”
Output − It doesn’t contains lowercase letter
The function given below will check the string whether it contains lowercase letter or not and if it contains lowercase letter then it will convert them to a uppercase.
Example
#include <stdio.h> #include <ctype.h> int main (){ int i=0; char str[]="Test String.\n"; char c; while (str[i]) { c=str[i]; if (islower(c)) c=toupper(c); putchar (c); i++; } return 0; }
Output
If we run the above code it will generate the following output −
TEST STRING.