We are all aware strings may be manipulated to upper- and lowercase. This article will describe how to convert a string to lowercase, both with and without using strlwr function in C.
What is Strlwr() Function in C?
Lowercase conversion is accomplished using the built-in C function strlwr(), which handles strings.
The words “str” and “lwr” stand for string and lower, respectively, as their names suggest.
Syntax: strlwr(char string);
A string is the string value that has to be changed.
Also Read: How to Change String into Uppercase without Strupr function in C?
Table of Contents
How to Convert String into Lowercase Using Strlwr Function in C?
An example of the strlwr() function in C is shown in the program below:
Code:
Char str[] =”HELLO wORld”;
defining the string variable str with the char data type.
printf(‘%s’,strlwr(str));
Lowercase conversion of the str value.
The code in the preceding paragraph will output the changed string created after lowercasing the characters in the string str provided.
Output: Hello world
Also Read: How to Compare two Strings Without Using Strcmp in C?
How to Convert String into Lowercase in C Without Using Strlwr Function in C?
Without strlwr(), an ASCII (American Standard Code for Information Interchange is the name of the acronym) value can convert a string to lowercase.
The letters and numbers 0 through 9 are included, along with a few unique symbols and the lowercase and capital letters A through Z.
Lowercase “a” to “z” ASCII codes range from 97 to 122, whereas uppercase “A” to “Z” ASCII codes range from 65 to 90.
To convert the string to lowercase without using strlwr(), use the following syntax:
int main()
//starting point for program execution.
{
char str[] = “HELLO wORld”;
//declare a str variable
int i = 0;
//integer type variable ‘i’ to keep track of string index.
while (s[i] != ‘\0’) {
//while loop to check the endpoint of the string.
if (s[i] >= ‘A’ && s[i] <= ‘Z’) {
//checking the ASCII range of the string.
s[i] = s[i] + 32;
//incrementing the value in case the ASCII range is between the uppercase range.
}
//end of the condition.
i++;
//increasing i i.e., i = i+1;
}
//end of while loop
printf(“%s”,str);
//print transformed str
}
//end of the main function