The tolower() method turns an uppercase alphabet to a lowercase letter. If the tolower() method is supplied inputs that are not uppercase alphabets, it returns the same character that was passed to the function. It is specified in the header file ctype.h.
In C programming, the character is saved as an integer. When a character is supplied as an argument, the character's matching ASCII value (integer) is passed instead of the character itself.
Example
Example 1
Let's take an example to understand the toLower() function by passing an uppercase, a lowercase and a special symbol as a parameter to the toLower() function.
#include <stdio.h>
#include <ctype.h>
int main()
char c, result;
c = 'A';
result = tolower(c);
printf("%c\n", result);
c = 'a';
result = tolower(c);
printf("%c\n", result);
c = '$';
result = tolower(c);
printf("%c\n", result);
return 0;
}
Output:
a a $
Example 2
Let's take a look at one more example to understand the toLower() function.
#include<stdio.h>
#include <ctype.h>
int main()
{
char ch;
ch = 'P';
printf("%c in lowercase is %c",
ch, tolower(ch));
return 0;
}
Which header file is used for the tolower() function?
tolower() function is defined in “ctype.h” header file which is included for converting any uppercase letter to lowercase.
What is the return type of the tolower() function?
The tolower() function returns a character type, as tolower() function is used for converting characters.
What happens when a lowercase character is passed as an argument?
If a lowercase character is passed into a tolower() function as an argument, then the same character is returned, and no case conversion happens.
What happens when a special character is passed as an argument?
If a special character is passed into a tolower() function as an argument, then the same character is returned, and no case conversion happens.
What happens when a string is passed as an argument?
If a string is passed into a tolower() function as an argument, then the last character of the string is returned in lowercase, and the case conversion is done.
Conclusion
In this article, we had a look at tolower() function in C and also learned its operation. We hope that this blog has helped you enhance your knowledge of tolower() function, and if you would like to learn more, check out our String functions articles on Coding Ninjas Studio. Do upvote our blog to help other ninjas grow. Happy Coding!!