Open In App
Related Articles

tolower() Function in C

Improve Article
Improve
Save Article
Save
Like Article
Like

tolower() function in C is used to convert the uppercase alphabet to the lowercase alphabet. It does not affect characters other than uppercase characters. It is defined in the <ctype.h> header file in C.

Syntax

The syntax of tolower() function is:

int tolower(int c);

Parameter

  • This function takes a character as a parameter.

Return Value

  • It returns the ASCII value corresponding to the lowercase of the character passed as the argument.

Examples of tolower() Function

Example 1

The below C program demonstrates the tolower() function.

C




// C program to demonstrate
// example of tolower() function.
#include <ctype.h>
#include <stdio.h>
 
int main()
{
 
    // convert 'M' to lowercase
    char ch = tolower('M');
 
    // Printing the lowercase letter
    printf("%c", ch);
 
    return 0;
}


Output

m

Example 2

The below code converts all uppercase letters in the string to their lowercase equivalents, while leaving other characters unchanged.

C




// C program to demonstrate
// example of tolower() function.
#include <ctype.h>
#include <stdio.h>
 
int main()
{
 
    char s[] = "Code_in_C_@0123";
 
    // This will just convert
    // uppercase letters in string
    // to lowercase. Other characters
    // will remain unaffected.
    for (int i = 0; i < strlen(s); i++) {
        s[i] = tolower(s[i]);
    }
 
    // Printing the output
    printf("%s", s);
 
    return 0;
}


Output

code_in_c_@0123

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 06 Jun, 2023
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials