In this source code example, we will see how to use the islower() function in C programming with an example.
islower() Function Overview
The islower() function is a member of the <ctype.h> library in C. This function determines if a given character is a lowercase letter from 'a' to 'z'.
Key Points:
- The function is available in the <ctype.h> header.
- It accepts an int as its argument, which typically represents a character.
- If the character is a lowercase letter, the function returns a non-zero value (true); otherwise, it returns 0 (false).
Source Code Example
#include <stdio.h> #include <ctype.h> int main() { char ch; printf("Enter a character: "); scanf("%c", &ch); if (islower(ch)) printf("'%c' is a lowercase letter.\n", ch); else printf("'%c' is not a lowercase letter.\n", ch); return 0; }
Output
Enter a character: a 'a' is a lowercase letter.
Explanation
1. We start by including the necessary header files: stdio.h for input/output functions and ctype.h for the islower() function.
2. In the main() function, we declare a character variable ch.
3. We then prompt the user to input a character.
4. The islower() function checks whether the given character is a lowercase letter.
5. Depending on the result, an appropriate message is printed to the console.
Comments
Post a Comment