Javatpoint Logo
Javatpoint Logo

Strlwr() function in C

Working with strings is a regular activity while programming in the C programming language. It is frequently necessary to transform strings to lowercase or uppercase to ensure uniform processing and comparisons. The strlwr() function is very crucial in this situation. It is a string manipulation function that can be found in the C Standard Library (string.h) and is used to change the case of characters in a string. In-depth explanations of the strlwr() function and a practical application example are provided in this article.

Every capital letter in a C-style string is changed to its corresponding lowercase character using the strlwr() function. One input, a reference to the string that must be transformed, is all that is required. The function makes the necessary modifications to the initial string while still returning the same pointer. It's crucial to remember that this method isn't standardized and cannot be accessible on all C implementations.


It has the following syntax:

str: It is a reference to the string that must be lowercase and has a null ending.

Value Returned:

The same pointer str is returned by the strlwr() method, which now points to the altered lowercase text.

The strlwr(string) function returns string characters in lowercase. Let's see a simple example of strlwr() function.


Enter string: JAVATpoint
String is: JAVATpoint
Lower String is: javatpoint


The relevant header files are first included in the code: stdio.h for input/output operations and string.h for functions involving string manipulation.

The input string will be saved in a 20-character array named str.

The printf() method asks the user to provide a string.

The gets() method reads the input string. It's crucial to remember that the gets() method is insecure and should be swapped out with fgets() to prevent buffer overflow. The printf() function prints the original input string.

After that, the str pointer is sent as an argument when using the strlwr() method. The method returns the changed text after changing all capital letters in the string to lowercase.

After that, the printf() function is used to output the lowercase string.

Problems with Safer Input Reading and gets()

The example's use of the gets() method brings up a serious issue with buffer overflow vulnerability. The function does not verify the input size, which might result in memory corruption. It is strongly advised to switch from gets() to fgets() for safer input reading. The updated code would seem as follows:


Enter string: HELLOworld
String is: HELLOworld
Lower String is: helloworld


In conclusion, the C language's strlwr() function offers an easy way to change uppercase to lowercase letters within a string, enabling case-insensitive operations and reliable string processing. Despite being frequently used, the function is non-standard and may not be included in all C implementations, which raises questions regarding portability.

The example code was advised against using gets(), and the safer substitute fgets() was suggested instead to solve potential security flaws. It is essential to ensure safe input handling to avoid buffer overflow and memory corruption problems.

Although strlwr() can effectively accomplish its goal, programmers should be aware of its limits and consider other standard-compliant approaches to string manipulation. It may be more portable to use bespoke functions in various C environments when converting lowercase strings.

Overall, being proficient with string manipulation in C, especially the proper application of methods like strlwr(), equips programmers to deal with strings quickly and write reliable, safe, and portable programs.

Next TopicC strupr()

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA