C Online Compiler
Example: String to Lowercase using tolower() in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// String to Lowercase using tolower() #include <stdio.h> #include <string.h> // For strlen #include <ctype.h> // For tolower void toLowerCase(char *str) { // Step 1: Iterate through the string until the null terminator is found. for (int i = 0; str[i] != '\0'; i++) { // Step 2: Use tolower() to convert the character to lowercase. // tolower() returns the lowercase equivalent if it's an uppercase letter, // otherwise, it returns the character itself unchanged. str[i] = tolower((unsigned char)str[i]); } } int main() { char myString[] = "HELLO, WORLD! 123"; printf("Original string: %s\n", myString); // Step 3: Call the toLowerCase function. toLowerCase(myString); printf("Lowercase string: %s\n", myString); return 0; }
Output
Clear
ADVERTISEMENTS