Javatpoint Logo
Javatpoint Logo

islower() in C

The islower() function is used to check whether the entered character passed inside the function is a lowercase character. The lowercase character includes (a-z).

Syntax of islower() In C Programming

int islower( int arg);

Parameters Passed in islower() Function

c: It requires only one parameter. The c represents a character that is required to be checked.

Return Value

Two possible values can be returned after using the islower() function. They can be

Non-zero value: It returns a non-zero value when the character passed to the islower() function is a lowercase character.

0: The function returns a zero (0) if the character is not lowercase.

Implementation of islower() function in C Programming

The islower() function in C Program checks that a character is typed in lowercase and not uppercase. It only returns a number other than zero if the character is one of them: a b c d e f g h i j k l m n o p q r s t u v w x y z.

The islower() function is declared in the ctype.h header file. It is necessary to include this header file to use this function as the function definition is in this file.

For any character the islower() function returns a non-zero value. The functions such as iscntrl, isdigit, ispunct and isspace will return zero for the same character.

For example:

Input value: z

Output: Non-zero value

Input value: U

Output: 0

Input value: $

Output: 0

Input value: c

Output: Non-zero value

Implement a C Program to Check Whether a Character is a lowercase character or not

Output:

islower() in C

The user can input any valid character from the keyboard. The program will pass that character into the islower() function, determining whether the character is in lowercase.

Using the islower() Function to write more complex programs

There are multiple applications of the islower() function. Some of these applications are implemented below:

Count the lowercase characters in a given string

Algorithm

To find out the number of lowercase characters in the string, we are required to follow these steps:

  1. Initialize a counter variable to zero.
  2. First, transverse the string character by character.
  3. Ensure that each character of the string is passed into the islower() function.
  4. Increment the value of the counter value by 1 whenever a non-zero value is returned by the islower() function.
  5. Use the break() statement to come out of the loop when the conditions have encountered the null character. The only drawback with this method is that the string should have only one null character at the end.
  6. Return the value of the counter value, representing the number of lowercase characters in the string. Print the value in your main function.

Output:

islower() in C

Print the Characters of the String Until you have encountered a Lowercase Character in the string

This is also a popular coding question. The aim is to print a string till you encounter the first lowercase character in the string. It is easy to code this problem by simply using the islower() function in the C Programming language.

Algorithm

  1. The first step is to transverse the string characters by character. Each character is once passed into the islower() function.
  2. The function returns a zero a character that is not in lowercase is passed into it. Use a loop to perform iteration. The condition for execution of the loop is that the islower() function should return Zero. So, if a non-lowercase character is passed in the function, it will return a non-zero value, the loop will execute, and the character will be printed.
  3. The loop will terminate itself once it encounters a lowercase character as it will break, resulting in coming out of the loop.

Let us code the actual program using the above algorithm.

Output:

islower() in C

Print the First Lowercase Character in the given string

Another application of the islower() function in C Programming is that we can easily determine the first lowercase character present in the string. Let us discuss two different approaches to solving this problem. One method to solve this is by performing iterations. The other method is by solving the problem using recursion in your code.

Iterative Approach

It is quite simple and straightforward. We will perform a linear search on the string. The difference is that here we will use the searching algorithm with the islower() function to find the very first lowercase character in the string.

Output:

islower() in C

Recursive Approach

Output:

islower() in C
Next Topicmemcpy() in C





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA