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 Lowercase character. The syntax of the tolower in C Programming language is

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

tolower(chars)

tolower in C Programming Example

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

//Example for C tolower
#include <stdio.h>
#include <ctype.h>

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

   printf("\n Your character is converted into Lower Case = %c", tolower(ch));         
}
Please Enter Any Character: 
M

 Your character is converted into Lower Case = m

First, we declared one character variable ch

char ch;

The below C Programming statement will ask to enter any character. And then we are assigning the user entered a character to ch variable

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

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

printf("\n Your character is converted into Lower Case = %c", tolower(ch));

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

Please Enter Any Character: 
8

 Your character is converted into Lower Case = 8

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

tolower in C Programming Example 2

A better approach to above mentioned C program

//Example for C tolower
#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

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 character to Lowercase using below statement

printf("\n Your character is converted into Lower Case = %c", tolower(ch));

If the above condition is FALSE, the given character is not Alphabet, and it will print the below statement

printf("\n Please Enter a Valid character");

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