Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Python Programs
    • Java Programs

tolower in C Programming

by suresh

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));         
}

OUTPUT

tolower in C Programming 1

ANALYSIS

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

tolower in C Programming 2

As you can see, 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"); 
   }
}

OUTPUT

tolower in C Programming 3

Let me enter the numeric value

tolower in C Programming 4

ANALYSIS

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.

Placed Under: C Programming

  • C Comments
  • C Escape Sequence
  • C Programming Operators
  • C Arithmetic Operators
  • C Assignment Operators
  • C Bitwise Operators
  • C Conditional Operator
  • C Increment & Decrement Optr
  • C Logical Operators
  • C Relational Operators
  • C Sizeof Operator
  • C If Statement
  • C IF ELSE Statement
  • C Else If Statement
  • C Nested If
  • C Break Statement
  • C Continue Statement
  • C Goto Statement
  • C Switch Case
  • C For Loop
  • C While Loop
  • C Do While Loop
  • C Arrays
  • C Two Dimensional Array
  • C Multi Dimensional Array
  • C String
  • C Structures
  • C Nested Structures
  • C Array of Structures
  • C Structures and Functions
  • C Union
  • C Structure & Union differences
  • C Pointers
  • C Pass Pointers to Functions
  • C GETS
  • C fgets Function
  • C fgetc
  • C fputs function
  • C fputc
  • C Functions
  • C Types of Functions
  • C Pass Array to Functions
  • Call By Value & Call By Reference
  • C Recursion
  • C Program Examples
  • C Tutorial
  • C# Tutorial
  • Java Tutorial
  • JavaScript Tutorial
  • Python Tutorial
  • MySQL Tutorial
  • SQL Server Tutorial
  • R Tutorial
  • Power BI Tutorial
  • Tableau Tutorial
  • SSIS Tutorial
  • SSRS Tutorial
  • Informatica Tutorial
  • Talend Tutorial
  • C Programs
  • C++ Programs
  • Java Programs
  • Python Programs
  • MDX Tutorial
  • SSAS Tutorial
  • QlikView Tutorial

Copyright © 2021 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy