
- C Library - Home
- C Library - <assert.h>
- C Library - <complex.h>
- C Library - <ctype.h>
- C Library - <errno.h>
- C Library - <fenv.h>
- C Library - <float.h>
- C Library - <inttypes.h>
- C Library - <iso646.h>
- C Library - <limits.h>
- C Library - <locale.h>
- C Library - <math.h>
- C Library - <setjmp.h>
- C Library - <signal.h>
- C Library - <stdalign.h>
- C Library - <stdarg.h>
- C Library - <stdbool.h>
- C Library - <stddef.h>
- C Library - <stdio.h>
- C Library - <stdlib.h>
- C Library - <string.h>
- C Library - <tgmath.h>
- C Library - <time.h>
- C Library - <wctype.h>
- C Programming Resources
- C Programming - Tutorial
- C - Useful Resources
C Library - tolower() function
The C ctype library tolower() function converts a given letter to lowercase. This function is useful in scenarios where case-insensitive processing of characters is required.
Syntax
Following is the C library syntax of the tolower() function −
int tolower(int c);
Parameters
This function accepts a single parameter −
c − The function takes a single argument of type int. This argument is an unsigned char value that can be implicitly converted to int, or it can be EOF. The value represents the character to be converted to lowercase.
Return Value
This function returns the lowercase equivalent of the character if it is an uppercase letter. If c is not an uppercase letter, the function returns c unchanged. If c is EOF, it returns EOF.
Example 1
The character 'A' is converted to 'a' using the tolower() function.
#include <stdio.h> #include <ctype.h> int main() { char ch = 'A'; char lower = tolower(ch); printf("Original: %c, Lowercase: %c\n", ch, lower); return 0; }
Output
The above code produces following result −
Original: A, Lowercase: a
Example 2: Converting a String to Lowercase
This example demonstrates how to convert an entire string to lowercase by iterating over each character and using tolower.
#include <stdio.h> #include <ctype.h> void convertToLower(char *str) { while (*str) { *str = tolower(*str); str++; } } int main() { char str[] = "Hello, World!"; convertToLower(str); printf("Lowercase String: %s\n", str); return 0; }
Output
After execution of above code, we get the following result
Lowercase String: hello, world!