Convert String to Lowercase in C Language

To convert a given string to lowercase in C language, iterate over characters of the string and convert each character to lowercase using tolower() function.

C Program

In the following program, we take a string in str, take a for loop to iterate over each character of this string, convert the character to lowercase using tolower() function, and store the result in result string.

Include ctype.h before using tolower() function.

Refer C For Loop tutorial.

main.c

</>
Copy
#include <stdio.h>
#include <ctype.h>

int main() {
    char str[30] = "Apple BANANA";

    char result[30];
    for (int i = 0; str[i] != '\0'; i++) {
        result[i] = tolower(str[i]);
    }
    
    printf("Input string      : %s\n", str);
    printf("Lowercase string  : %s\n", result);
    
    return 0;
}

Output

Input string      : Apple BANANA
Lowercase string  : apple banana
Program ended with exit code: 0

Conclusion

In this C Tutorial, we learned how to convert a given string to lowercase using tolower() function.