C C++ Java Data Structure Python JavaScript CSS Ajax PL/SQL PHP Puzzles C programs C++ programs Java programs



Home » C programs » ctype.h header file functions

tolower() function of ctype.h in C






In this article, we are going to learn about the tolower() function of ctype.h header file in C programming language and use it to convert the uppercase variables in lowercase.
Submitted by Abhishek Sharma, on April 11, 2018

This function is used to make an upper-case character into the lower-case character. This function takes a character in the form of a parameter as a character and returns a character. The Character which will return will be in lower-case.

This is rather useful function and makes coding simple. This can be used in different scenario, like printing the output in the particular format irrespective of the user’s input.

Anyway you can implement your own function if you don’t want to include a whole library in your program. Just check for the ascii value and modify them.

Example:

    Input character is: 'A'
    Function will return 'a'


    Input character is: 'a'
    Function will return 'a'



ctype.h - tolower() function Example in C

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

int main()
{
	// defining the type of variable
	char a,b,c,d,e,f,g,h,i,j;

	// assigning the value of variables
	a = 'A';
	b = 'B';
	c = 'C';
	d = 'D';
	e = 'E';

	// getting the lower case values of 
	// the above assigned variables
	f = tolower(a);
	g = tolower(b);
	h = tolower(c);
	i = tolower(d);
	j = tolower(e);


	// printing the upper case and their lower case values

	printf("Lowercase '%c' is '%c'\n", a, f);

	printf("Lowercase '%c' is '%c'\n", b, g);

	printf("Lowercase '%c' is '%c'\n", c, h);

	printf("Lowercase '%c' is '%c'\n", d, i);

	printf("Lowercase '%c' is '%c'\n", e, j);

	return 0;
}

Output

ctype.h - tolower()  in c language







You may also be interested in...

C/C++ Tips and Tricks...

Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.


Comments and Discussions