tolower in C Programming

The tolower function is one of the Standard Library Functions available in C language, which is useful to convert the user-specified character into a Lowercase character. The syntax of the tolower is

The following function will accept the character as the parameter and convert the given character to lowercase using the tolower in C Programming language.

tolower(chars)

tolower in C Programming Example

The tolower method is used to convert the given character to lowercase. This C program allows the user to enter any letter and convert that character to lowercase using the tolower function.

#include <stdio.h>
#include <ctype.h>

int main()
{
   char ch;
   printf("Please Enter Any Character: \n");
   scanf("%c", &ch);

   printf("\nLower Case = %c", tolower(ch));         
}
Please Enter Any Character: 
M

Lower Case = m

First, we declared one character variable, ch. The next C Programming printf statement will ask to enter any letter. And then, we assign the user entered one to ch variable.

Next, we used the tolower() function directly inside the printf statements to print the output. The following statement will convert the letter in the ch variable to lowercase.

printf("\nLower Case = %c", tolower(ch));

The above code will convert the given letter to lowercase, but what if we enter the numeric value?

Please Enter Any Character: 
8

Lower Case = 8

It is not throwing any error, which is not good in real-time.

Example 2

A better approach to above mentioned C program

Here we added the If Statement to check whether the character is between ‘A’ and ‘Z’. If the condition is True, it will convert the given letter to Lowercase.

If the above condition is FALSE, the given letter is not Alphabet, and it will print the else block statement.

Please refer Program to Convert Lowercase article. It helps you understand how to convert the character to lowercase without using the tolower function.

#include <stdio.h>
#include <ctype.h>

int main()
{
   char ch;
   printf("Please Enter Any Character: \n");
   scanf("%c", &ch);

   if(isalpha(ch))
   {
      printf("\n Your character is converted into Lower Case = %c", tolower(ch));         
   }
   else
   {
      printf("\n Please Enter a Valid character"); 
   }
}
tolower in C Programming 3

Let me enter the numeric value.

Please Enter Any Character: 
9

 Please Enter a Valid character