C Program to Convert Character to Lowercase

How to convert the given character to lowercase in C using tolower built-in function and not to use tolower function. The C Programming tolower is a built-in function present in the header file, which is useful to convert the character to uppercase. The Syntax of the C tolower function is

tolower (<Character>);

C Program to Convert Character to Lowercase using tolower function

This C program allows the user to enter any character and convert the character to lowercase using the built-in ctype function called tolower.

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

int main()
{
  char Ch;

  printf("\n Please Enter any alphabet\n");
  scanf(" %c", &Ch);
  
  if (isalpha(Ch) )
   {  
     Ch = tolower(Ch); 
     printf ("\n Lowercase of Entered character is %c", Ch);
   }
  else
   {
     printf("\n Please Enter Valid Alphabet");
   }  
}

uppercase to Lowercase in c output

 Please Enter any alphabet
K

 Lowercase of Entered character is k

In this C Program to Convert Character to Lowercase, we used the If Statement,

if (isalpha(Ch) )

If the above condition is TRUE, then the given character is an Alphabet. And now, we can convert the given character to Lowercase using below statement

Ch = tolower(Ch);

In the next line, we have the C programming printf statement to print the converted Lowercase letter.

printf ("\n Lowercase of Entered character is %c", Ch);

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

printf("\n Please Enter Valid Alphabet");

C Program to Convert Character to lowercase without using tolower function

This C program allows the user to enter any character and change the character to lowercase without using a built-in ctype function tolower.

In this example, we use the ASCII code to convert an uppercase character to lowercase. Please refer ASCII Value of a Character article to understand the ASCII values of every character.

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

int main()
{
  char Ch;
 
  printf("\n Please Enter any alphabet\n");
  scanf(" %c", &Ch);

  if (isalpha(Ch) )
  {
    if (Ch>=65 && Ch<=90)
     {  
       Ch = Ch + 32; 
       printf ("\n Lowercase of Entered character is %c", Ch);
     }
    else
     {
       printf("\n You Already Entered Lowercase Character");
     }  
   }
  else
   {
     printf("\n Entered character is Not an Alphabet");
   }  
}
C program to Convert Character to Lowercase without using ToLower 0

Let us see what happens when we enter Lowercase letter as Ch

 Please Enter any alphabet
m

 You Already Entered Lowercase Character

Now, Let us see what happens when we enter Digit as Ch

 Please Enter any alphabet
9

 Entered character is Not an Alphabet

Within this C Program to Convert Character to Lowercase, If you look at the Nested If Statement

if (Ch>=65 && Ch<=90)

//or We can Simply Say
if (Ch >= 'A' && Ch <= 'Z')

As we all know that, all the uppercase characters are between A and Z, and their ASCII codes are 65 to 90. So, the above if condition will check whether the given character is between A and Z.

If the above condition is TRUE, then we have to convert the given character to lowercase. If you observe the ASCII codes of uppercase and lowercase letters, the difference between them is 32. For instance, ASCII code for a = 97 & A = 65 (Difference is 32). That’s why we were adding 32 to the character ASCII value.

Ch = Ch + 32;

In the next line, we have the printf statement to print the converted Lowercase letter

printf ("\n Lowercase of Entered character is %c", Ch);

If the above condition is FALSE, the given character is already in lowercase So, it will print the below statement.

printf("\n You Already Entered Lowercase Character");