The tolower() function defined in the ctype.h header file. It helps to convert the given uppercase character into a lowercase character.
int tolower(int argument); #where argument will be a character
The tolower() function takes a single parameter and is in the form of an integer. When a character is passed it is converted into the integer value corresponding to its ASCII value.
Parameter | Description | Required / Optional |
---|---|---|
argument | The character needs to be converted | Required |
This function converts the given uppercase character to a lowercase character. The value is returned as an int value that can be implicitly cast to char. If the passed argument is not an uppercase letter it will return the same passed character.
Input | Return Value |
---|---|
uppercase character | corresponding lowercase character |
lowercase character or a non-alphabetic character | the character itself |
#include <stdio.h>
#include <ctype.h>
int main()
{
char ch, output;
ch = 'A';
output = tolower(ch);
printf("tolower(%c) = %c\n", ch, output);
ch = 'a';
output = tolower(ch);
printf("tolower(%c) = %c\n", ch, output);
ch = '+';
output = tolower(ch);
printf("tolower(%c) = %c\n", ch, output);
return 0;
}
Output:
tolower(A) = a tolower(a) = a tolower(+) = +
#include <stdio.h>
#include <ctype.h>
int main () {
int k = 0;
char ch;
char st[] = "PROGRAMMING";
while( st[k] ) {
putchar(tolower(st[k]));
k++;
}
return(0);
}
Output:
programming