strlwr() in C
×


strlwr() in C

52

 strlwr() is the function responsible for converting a string to lowercase.

 It takes a string str as input and converts all uppercase letters in the string to lowercase.

After applying strlwr(), the original string str is transformed into its lowercase form.

Imagine you have a string with both uppercase and lowercase letters, like "Hello, World!".

strlwr() helps you convert all the uppercase letters in the string to lowercase.

It's like changing all the capital letters to small letters, making the string completely lowercase.

Example:

// Program for strlwr() in c
#include<stdio.h> #include<string.h> int main() { char str[100]; // Declare a character array to store the string // Input the string from the user printf("Enter a string: "); fgets(str, sizeof(str), stdin); // Convert the string to lowercase for (int i = 0; str[i] != '\0'; i++) { if (str[i] >= 'A'&& str[i] <= 'Z'){ str[i] += 32; // Convert lowercase lowercase to uppercase } } // Print the string in uppercase printf("String in uppercase: %s\n", str); return 0; }

Output:

Enter a string: siya
String in uppercase: siya

 We loop through each character in the string.

 If the character is an uppercase letter (between 'A' and 'Z' in ASCII), we add 32 to convert it to lowercase (since in ASCII, the difference between the uppercase and lowercase letters is 32).

 Finally, we print the modified string, which is now in lowercase.

Advantages of strlwr() function 

 Simplicity: strlwr() makes converting strings to lowercase easy without the need for complex logic.

 Efficiency: It quickly converts uppercase letters to lowercase, saving time and effort.

 Versatility: You can use strlwr() on any string containing uppercase letters, regardless of its length or content.

 Standard Function: strlwr() is a standard function in C, widely used and understood by programmers.



Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments