strlwr() Function in C

In the C programming language, the strlwr() function is used to convert a string to lowercase. This function is part of the string.h library and is commonly used in text processing and manipulation tasks.

The strlwr() function takes a string as input and modifies it in place, converting all uppercase characters to their lowercase equivalents. The function returns a pointer to the modified string.

Here is an example usage of the strlwr() function:

#include 
#include 

int main() {
   char str[] = "HELLO WORLD";
   
   printf("Original string: %sn", str);
   
   char* convertedStr = strlwr(str);
   
   printf("Converted string: %sn", convertedStr);
   
   return 0;
}

In this example, the str[] array is initialized with the string “HELLO WORLD”. The strlwr() function is then called with the str array as the argument. The converted string is stored in the convertedStr pointer, which is then printed to the console.

After running this program, the output will be:

Original string: HELLO WORLD
Converted string: hello world

As you can see, the strlwr() function has successfully converted all uppercase characters in the string to lowercase.

It is important to note that the strlwr() function only works with ASCII characters. If the string contains any non-ASCII characters, the behavior of the function is undefined. Additionally, the strlwr() function modifies the original string in place, so it is advisable to make a copy of the string if the original needs to be preserved.

Here are a few key points to keep in mind when using the strlwr() function:

  • The strlwr() function is defined in the string.h library, so make sure to include this header file in your program.
  • The function takes a string as input and modifies it in place.
  • The function only works with ASCII characters and has undefined behavior with non-ASCII characters.
  • It is recommended to make a copy of the original string if it needs to be preserved.

Overall, the strlwr() function is a useful tool for converting strings to lowercase in C. It provides a convenient way to perform case-insensitive string comparisons and other text processing tasks. Just remember to handle non-ASCII characters with caution and make copies of the original string when necessary.

Scroll to Top