Return: a non-zero value if int c is a lowercase alphabetic value. Otherwise, 0.
Parameter list: (int
c) - the character that is checked to determine the return value.
Header file:<ctype.h>.
1. So, what is the islower function in C?
The islower function in C programming language checks the input value to determine if it is a lowercase character. The lowercase characters in C have ASCII values in the range of [97, 122]. Meaning that if the input value is more or equal to 97 and less or equal to 122, then it is a lowercase character. In such a case, the islower function returns a non-zero value. If the input value is outside of the mentioned range, then 0 is return.
Example 1: Usage example of the islower function in C.
#include<ctype.h>
#include<stdio.h>
intmain(void)
{
printf("1. %d\n",islower('a'));
printf("2. %d",islower('A'));
return(0);
}
Possible output:
1. 1
2. 0
2. How to rewrite the islower function in
C?
Now, to implement the islower function accurately, we need to satisfy the following three conditions:
Check if the input value is within the range of lowercase alphabetic characters.
Return a non-zero result, if the input value is within the lowercase range.
Return 0, if it is not within the range.
Example 2: Rewritten islower function in C.
intour_islower(intc)
{
if( c>=97&&c<=122 )
return(1);
return(0);
}
You can see (on line 3) a conditional statement, which checks if the c value is within the lowercase character range. It returns true, when the received parameter is a lowercase character and so 1 will be returned (on line 4). If this conditional statement returns false, then a zero will be returned (on line 5).
3. Testing the rewritten islower function
Now that we have our_islower function implemented, it is a good time to test it. For that we are going to compare the return values of our_islower function with the original standard library function with a couple of values.
Example 3: Test of the rewritten islower function in C.