C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

Strings in C

Convert string to lowercase

C Program: Convert String to Lowercase (without using strlwr())

C

#include <stdio.h>

 

int main() {

    char str[200];

    int i;

 

    // Input string safely

    printf("Enter a string: ");

    fgets(str, sizeof(str), stdin);

 

    // Convert to lowercase

    for (i = 0; str[i] != '\0'; i++) {

        if (str[i] >= 'A' && str[i] <= 'Z') {

            str[i] = str[i] + 32;  // Convert uppercase to lowercase

        }

    }

 

    printf("Lowercase string: %s", str);

 

    return 0;

}

Output

 
OUTPUT :
Enter a string: IT DEVELOPER
Lowercase string: it developer

Explanation

  • This program reads a string and converts all uppercase characters ('A' to 'Z') into lowercase by adding 32 to their ASCII value.
  • The conversion ignores other characters (digits, spaces, punctuation).