Islower In C

int islower( int arg);

Parameters Passed in islower Function

It demands just a single argument. The c denotes a character that needs to be verified.

Return Value

Two potential outcomes are possible following the utilization of the islower method. These outcomes include:

Non-empty result: When a lowercase character is input into the islower function, it yields a non-empty result.

The function will output a zero (0) if the character is not in lowercase.

Implementation of islower function in C Programming

The islower function in a C program verifies whether a character is in lowercase or not in uppercase. It will only yield a non-zero value if the character falls within the range of lowercase alphabets from a to z.

The islower function is specified in the ctype.h header file. To utilize this function, it is essential to include the aforementioned header file since the function's implementation is contained within it.

For each character, the islower function yields a value other than zero. Conversely, the iscntrl, isdigit, ispunct, and isspace functions will provide a return value of zero for that identical 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

Example

#include <stdio.h>
// including ctype to use the islower() function in your code
#include <ctype.h>
int main()
{
//take the character as an integer value.
int character; //Ascii value of the character
printf("Enter a character from the keyboard ");
character = fgetc(stdin);
//using the function for checking character is between(a-z)
//if it is (a-z) then it will return 0
if (islower(character) == 0)
{
printf("%c is not a lowercase character.", character);
}
// in every other case else statement will be executed.
else
{
printf("%c is a lowercase character.", character);
}
return 0;
}

Output:

Output

Enter a character from the keyboard %c is not a lowercase character.%c is a lowercase character.

The user has the option to enter any valid keyboard character. The software will then send this character to the islower function to check if it is a lowercase character.

Utilizing the islower method for developing more intricate applications

There are various uses of the islower method. Below are a few examples demonstrating its functionality:

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:

  • Initialize a counter variable to zero.
  • First, transverse the string character by character.
  • Ensure that each character of the string is passed into the islower function.
  • Increment the value of the counter value by 1 whenever a non-zero value is returned by the islower function.
  • 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.
  • Return the value of the counter value, representing the number of lowercase characters in the string. Print the value in your main function.
  • Example
    
    //Include all the necessary libraries
    #include <ctype.h>
    #include<string.h>
    #include <stdio.h>
    unsigned int TotalLowercase(char *strng)
    {
    unsigned int counter = 0;
    //check if string is valid or not
    if (strng != NULL)
    {
    //count the occurrence of lowercase characters
    //increment whenever a lowercase character is encountered
    for(int i=0;strng[i]!=0;i++)
    {
    if (islower((unsigned char)strng[i]))
    {++counter;
    }
    }
    }
    // return the value of counter once null character is reached in the given string.
    return (counter);
    }
    int main()
    {
    char strng[] = "This is the Content for Logic Practice";
    unsigned int counter = TotalLowercase(strng);
    printf("The count of characters in the given string is %u\n\n", strlen(strng));
    printf("\nThe number of lowercase characters in the given input stream is : %u\n\n", counter);
    return 0;
    }
    

Output:

Output

Enter a character from the keyboard %c is not a lowercase character.%c is a lowercase character.

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

This is a common coding challenge where the task is to display a string until the first occurrence of a lowercase letter. You can solve this problem efficiently by utilizing the islower function in the C programming language.

Algorithm

  • The first step is to transverse the string characters by character. Each character is once passed into the islower function.
  • 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.
  • The loop will terminate itself once it encounters a lowercase character as it will break, resulting in coming out of the loop.

Let's implement the real program utilizing the algorithm mentioned above.

Example

//Include all the necessary libraries
#include <ctype.h>
#include<string.h>
#include <stdio.h>
int main()
{
char str[] = "THIS IS THE STRING PRINTeD TILL FIRST lowercase character";
unsigned int i = 0;
//Print the String until the first character
//loop executes till the condition is false
while (!islower((unsigned char)str[i]))
{
putchar(str[i]);
i++;
}
return 0;
}

Output:

Output

Enter a character from the keyboard %c is not a lowercase character.%c is a lowercase character.

Print the First Lowercase Character in the given string

One alternative use of the islower function in C Programming is the ability to identify the initial lowercase character within a string. Let's explore two distinct strategies for addressing this issue. One technique involves employing iterative processes, while the other approach entails implementing recursion within your code.

Iterative Approach

It's fairly uncomplicated and direct. We will execute a linear exploration on the given string. The variation lies in utilizing the search algorithm alongside the islower method to identify the initial lowercase character within the string.

Example

#include <ctype.h>
#include<string.h>
#include <stdio.h>
char firstLowerCharacter(char *strng)
{
unsigned int i = 0;
char firstLowercaseCharacter = 0;
//Check if the string is valid or not
if (strng != NULL)
{
//
// find first lowercase char
while (strng[i] != '\0')
{
if (islower((unsigned char)strng[i]))
{
//break as the first lowercase character will be encountered
firstLowercaseCharacter = strng[i];
break;
}
++i;
}
}
//it will return the first lowercase character in the string
return (firstLowercaseCharacter);
}
int main()
{
//String must have only one null char (terminating null)
char strng[] = "LET US CHECK FOR THE fIRST LOWERCASE CHARACTER.";
unsigned int firstLowercaseCharacter = firstLowerCharacter(strng);
if(firstLowercaseCharacter != 0)
{
printf("The number of characters in the string are: %u\n\n", strlen(strng));
printf("\nThe first lowercase character typed in the string is: %c \n\n", firstLowercaseCharacter);
}
else
printf("There is no lowercase character in the string.");
return 0;
}

Output:

Output

Enter a character from the keyboard %c is not a lowercase character.%c is a lowercase character.

Recursive Approach

Example

#include <ctype.h>
#include<string.h>
#include <stdio.h>
char firstLowerCharacter(char * strng, int i)
{
if (strng != NULL)
{
if (strng[i] == '\0')
{
return 0;
}
if (islower(strng[i]))
{
return strng[i];
}
}
return firstLowerCharacter(strng, i+1);
}
int main()
{
//The string should only have one null character in it
//that is in the end of the string marking the end of the string
char strng[] = "LET US CHECK FOR THE FIRST lowerCASE CHARACTER";
unsigned int firstLowerCaseChar = firstLowerCharacter(strng, 0);
if(firstLowerCaseChar != 0)
{
printf("The number of characters in the string are: %u\n\n", strlen(strng));
printf("\nThe first lowercase character typed in the string is: %c \n\n", firstLowerCaseChar);
}
else
printf("There is no lowercase character in the string.");
return 0;
}

Output:

Input Required

This code uses input(). Please provide values below: