tolower() Function in C
The tolower() capability is characterized in the ctype.h header document. In the event that the person passed is a capitalized letter set, the tolower() capability switches capitalized letters in order over completely to lowercase letters in order.
Syntax:
int tolower(int ch);
Essentially tolower() returns an int esteem, and in C language, we can client %c to switch that int esteem over completely to roast worth. However, in c++, pigeonholing is required this way:
char c = (char) tolower(‘A’);
Parameters: This strategy takes a compulsory boundary ch which is the person to be switched over entirely to lowercase.
Return Value: This capability returns the lowercase person compared to the ch.
Example:
// Simple C program to demonstrate the tolower() function
// example of tolower() function in C.
#include <ctype.h> //here, we are including the ctype.h module into our program
#include <stdio.h> //here, we are including the stdio.h module into our program
#include <conio.h> //here, we are including the conio.h module into our program
int main()
{
// here, we are giving the input as Characters that are to be converted to the //Lowercase Characters
char ch = “Vijay”;
clrscr(); //this function is used to clear the screen before printing the characters
// here, we are converting the ch data to the lowercase character using toLower() //function
printf(“Hello World, Welcome to the program”); //here, we are printing the //simple output statement
printf("The given %c in lowercase is represented as = %c", ch, tolower(ch));
return 0;
}
Output:
Hello world, Welcome to the program.
The given Vijay in lowercase is represented as = vijay
Example 1:
// Simple C program to demonstrate the tolower() function for more than 2 //characters
// Example of tolower() function in C.
#include <ctype.h> //here, we are including the ctype.h module into our program
#include <stdio.h> //here, we are including the stdio.h module into our program
#include <conio.h> //here, we are including the conio.h module into our program
int main()
{
int j = 0; //here, we are initializing a integer j assigned to 0
char st[] = "VIJAY kUMAR\n";
// the above is the given Character that is to be converted to lowercase
char ch = 'V';
clrscr(); //this function is used to clear the screen before printing the characters
// here, we are converting every character to lowercase
printf(“Hello World, Welcome to the program”); //here, we are printing the //simple output statement
while (st[j]) { //here, we are declaring a while loop to convert every single
// character to the lowercase
str[j] = tolower(str[j]);
j++; //here, we are reading every single character of the word
}
// here, we are printing the string that is converted into lowercase
for (int i = 0; i < j; i++) //here, we are using the for loop to print every character
printf(“Printing the characters in lower case:”);
printf("%c", str[i]); //here, we are printing the characters
return 0;
}
Output:
Hello World, Welcome to the program
Printing the characters in lowercase: vijay kumar
Note:
Assuming the character passed in the tolower() is any of these three
1. lowercase person
2. unique image
3. digit
tolower() will return the character for what it's worth.
Example 2:
// Simple C program to demonstrate the tolower() function for more than 2 //characters and special characters
// Example of tolower() function in C.
#include <ctype.h> //here, we are including the ctype.h module into our program
#include <stdio.h> //here, we are including the stdio.h module into our program
#include <conio.h> //here, we are including the conio.h module into our program
int main()
{
int j = 0; //here, we are initializing a integer j assigned to 0
char st[] = "[email protected]\n"; //here, we are initializing the Character st with some //uppercase, lowercase and special characters
char ch; //here, we are declaring the character variable ch
printf(“Hello World, Welcome to the program”); //here, we are printing the //simple output statement
printf(“Printing the characters in lowercase”);
while (str[j]) { //here, we are declaring a while loop to convert every single
// character to the lowercase
ch = str[j];
putchar(tolower(ch)); //here, we are converting the uppercase characters to //the lowercase characters
j++;
}
return 0;
}
Output:
Hello World, Welcome to the program.
Printing the characters in lowercase:
[email protected]