What is tolower in c programming?
tolower in c is a c library function which converts given uppercase letters to lowercase letters.
This function is defined in ctype.h header file.
It returns converted lowercase letters as integer which is then casted to char.
If the given input value doesn’t exist then it remains unchanged.
Prototype
#include<ctype.h>
int tolower(int x);
Parameters
This function takes characters to be converted to lowercase.
Return value
This function returns converted lowercase letters as int which is then casted to char.
Example program for tolower function in c
Example 1
//tolower in c example 2
#include<stdio.h>
#include<ctype.h>
int main()
{
int i=0;
char string[30]="SCHOLARSOUL";
while(string[i])
{
string[i]=tolower(string[i]);
i++;
}
printf("The result is %s \n",string);
return 0;
}
Code explanation
The input value is being converted from uppercase to lowercase by passing it to the tolower function. The result is being printed onto the console.
Example 2
//tolower in c example 2
#include<stdio.h>
#include<ctype.h>
int main()
{
int i=0;
char string[30];
printf("\n\n\tEnter the input in uppercase \n\t");
scanf("%s",string);
while(string[i])
{
string[i]=tolower(string[i]);
i++;
}
printf("\n\tThe result is %s \n\n",string);
return 0;
}
Code explanation
First, we have to include the stdio.h header file in order to use tolower function to perform the operation. That we have done using #include
macro.
Then we have to include ctype.h header file.
We take input from user and pass it to tolower function as input.
The result is printed on console.
Difference between tolower and toupper in c
tolower is a c library function that converts given uppercase letters to lowercase letters. toupper is a c library function that converts lowercase letters to uppercase letters.
tolower function returns converted lowercase letters as an integer which is then cast to char. toupper function returns converted uppercase letters as an integer which is then cast to char.
Prototypes are as follows
int tolower(int x);
int toupper(int y);
tolower | toupper |
Converts given uppercase letter to lowercase letters. | Converts lowercase letters to uppercase letters. |
int tolower(int x); | int toupper(int y); |
Difference between tolower and islower in c
tolower is a c library function that converts given uppercase letters to lowercase letters. islower function checks whether a character is in lowercase or not.
tolower function returns converted lowercase letters as an integer which is then cast to char. islower function returns a non-zero number if a given character is in lowercase letter otherwise zero.
Prototypes are as follows
int tolower(int x);
int islower(int y);
tolower | islower |
Converts uppercase letters to lowercase letters. | Checks a given character is in lowercase or not. |
int tolower(int x); | int islower(int y); |
People also ask for
What is the difference between tolower and isalpha in c?
tolower is a c library function that converts given an uppercase letter to lowercase. isalpha function checks whether a character is an alphabet or not.
What is tolower in c?
tolower in c converts uppercase letters to lowercase letters. It is defined in ctype.h header.