Strlwr in C Programming

The C Strlwr function is a C String Function, used to convert the user-specified characters or string into Lowercase letters. The following C Programming strlwr function will accept the characters as the parameter and convert all the characters in a string to lowercase using the built-in String function Strlwr.

strlwr(chars)

Strlwr in C Programming Example

The C strlwr function converts all the characters in a given string into lowercase. This program will help you to understand the same.

NOTE: You have to include the #include<string.h> header before using any C String Function.

//strlwr in C Programming
#include <stdio.h> 
#include<string.h>

int main()
{
	char str[] = "C LanGUAGE Tutorial AT TUTORIal GATEWaY";
		
	char str1[] = "C LaGUagE";
	char str2[] = "Java Programming Language";
	char str3[] = "c PRogramms";
	char str4[] = "TrY tO ReAd ThIs SenTEnCe";
			
 	printf("\n Lower Case String is = %s", strlwr(str));
 	printf("\n Lower Case String is = %s", strlwr(str1));
 	printf("\n Lower Case String is = %s", strlwr(str2));
 	printf("\n Lower Case String is = %s", strlwr(str3)); 	
  	printf("\n Lower Case String is = %s", strlwr(str3)); 		
}
Strlwr in C Programming 1

In this C strlwr function example, First, we declared five-character arrays str, str1, str2, str3, str5, and by using the following statement we assigned characters to each character array

char str[] = "C LanGUAGE Tutorial AT TUTORIal GATEWaY";
char str1[] = "C LaGUagE";
char str2[] = "Java Programming Language";
char str3[] = "c PRogramms";
char str4[] = "TrY tO ReAd ThIs SenTEnCe";

Next, we used the C strlwr method directly inside the printf statements to print the output. The following C Programming statements will convert the previously declared String data into lowercase.

printf("\n Lower Case String is = %s", strlwr(str));
printf("\n Lower Case String is = %s", strlwr(str1));
printf("\n Lower Case String is = %s", strlwr(str2));
printf("\n Lower Case String is = %s", strlwr(str3)); 	
printf("\n Lower Case String is = %s", strlwr(str3));

C Program to convert string to Lowercase without Strupr

This program will help you to understand how to write a C program to convert the given string into the Lower case without using the built-in string function strlwr.

#include <stdio.h> 
void String_Lower(char []);
 
int main()
{
	char str[100]; 
	printf("\n Please Enter a string to convert it into Lowercase\n");
	gets(str);
 
	String_Lower(str); 
	printf("\n Lower Case String is = %s", str); 
	return 0;
}
 
void String_Lower(char string[]) 
{
	int i = 0; 
	while (string[i] != '\0') 
	{
    	if (string[i] >= 'A' && string[i] <= 'Z') {
        	string[i] = string[i] + 32;
    	}
      	i++;
	}
}
 Please Enter a string to convert it into Lowercase
HELLO C PROGRAMMING WORld

 Lower Case String is = hello c programming world

In this string lower in C without strlwr function example, the First printf statement will ask the user to enter any name or string. And the user-specified string will be assigned to character array str[100].

printf("\n Please Enter a string to convert it into Lowercase\n");
gets(str);

The following statement will call the function void String_Lower(char string[])

String_Lower(str);

For every string, the special character \0 automatically added to the end, and it acts as marking where the string will end. So in the while loop, we check for the same:

while (string[i] != '\0')
  • While loop will continue iterating until it reaches the special character \0. Once it reached then, the loop will terminate.
  • In the next line, we used the If Statement to check whether the character is between ‘A’ and ‘Z’. If the condition is True, we are adding 32 to existing ASCII values. It is because the ASCII value of A is 65, and a is 97. To convert a to A, we are adding 32 to it.
  • Next line, we increment the value of i. Please refer ASCII Table article to understand the list of ASCII characters and their decimal, Hexadecimal, and Octal numbers.