tolower() Function in C
tolower() function in C is used to convert the uppercase alphabet to the lowercase alphabet. It does not affect characters other than uppercase characters. It is defined in the <ctype.h> header file in C.
Syntax
The syntax of tolower() function is:
int tolower(int c);
Parameter
- This function takes a character as a parameter.
Return Value
- It returns the ASCII value corresponding to the lowercase of the character passed as the argument.
Examples of tolower() Function
Example 1
The below C program demonstrates the tolower() function.
C
// C program to demonstrate // example of tolower() function. #include <ctype.h> #include <stdio.h> int main() { // convert 'M' to lowercase char ch = tolower ( 'M' ); // Printing the lowercase letter printf ( "%c" , ch); return 0; } |
Output
m
Example 2
The below code converts all uppercase letters in the string to their lowercase equivalents, while leaving other characters unchanged.
C
// C program to demonstrate // example of tolower() function. #include <ctype.h> #include <stdio.h> int main() { char s[] = "Code_in_C_@0123" ; // This will just convert // uppercase letters in string // to lowercase. Other characters // will remain unaffected. for ( int i = 0; i < strlen (s); i++) { s[i] = tolower (s[i]); } // Printing the output printf ( "%s" , s); return 0; } |
Output
code_in_c_@0123
Please Login to comment...