Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c

What is iswlower in C?

Talha Ashar

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The iswlower function in C checks whether a given wide character is a lowercase character, i.e., a letter between aza-z.

A wide character is similar to the normal character data type, except it represents the Unicode character set instead of the ASCII character set.

To use the iswlower function, you will need to include the <wctype.h> library in the program, as shown below:

#include <wctype.h>

The prototype of the iswlower function is shown below:

int iswlower(wint_t ch);

Note: The wint_t data type shown above refers to a wide integer in C.

Parameters

The iswlower function takes a single mandatory parameter of the wide integer data type.

Return Value

If the argument passed to the iswlower function is a lowercase character, then the function returns a non-zero integer; otherwise, it returns 00.

Example

The code below shows how the iswlower function works in C:

#include <stdio.h>
#include <wctype.h>
#include <wchar.h>
int main() {
// initializing string
wchar_t str[] = L"aBcFTr";
// extracting characters
for(int i = 0; i < wcslen(str); i++)
{
// checking if lowercase
if(iswlower(str[i]))
{
printf("The character \'%c\' is in lowercase.\n", str[i]);
}
else
{
printf("The character \'%c\' is not in lowercase.\n", str[i]);
}
}
return 0;
}

Explanation

First, the program declares a character array consisting of both lowercase and uppercase characters. The ‘L’ identifier in line 8 informs the compiler that the Unicode character set is being used.

A for-loop iterates over this array and extracts each character. The wcslen function calculates the array’s length so that the loop can terminate correctly.

Each extracted character is provided as an argument to the iswlower function in line 15. The iswlower function proceeds to check if the character is a lowercase letter and outputs the result accordingly.

RELATED TAGS

c

CONTRIBUTOR

Talha Ashar
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring