C Program to Convert Uppercase String to Lowercase

  • Write a C program to convert uppercase alphabets to lowercase in a string.
  • How to convert alphabets from uppercase to lowercase.

We first take a string as input from user. We have to convert all uppercase alphabets of input string to lowercase alphabets.
For Example
Input String: ApPLe
Output String: apple

C program to convert uppercase to lowercase using strlwr function

This program first takes a string as input from user using gets function and stores it in a character array 'inputString'. It calls strlwr function by passing inputString and prints it's response on screen.
Function strlwr is used to convert all characters of a string to lowercase. Here is the declaration for strlwr function.

char *strlwr(char *string);

/*
* C Program to change uppercase characters 
* to lowercase characters in a string using strlwr function
*/
#include <stdio.h>
#include <conio.h>
#include <string.h>

int main(){
    char inputString[100];
    int index;
    printf("Enter a String\n");
    gets(inputString);    
    printf("String with all lowercase characters \n%s ", 
        strlwr(inputString));

    getch();
    return 0;
}
Program Output
Enter a String
TechCrashCourse
String with all lowercase characters
techcrashcourse

C program to convert uppercase to lowercase using isupper and tolower function

Function isupper check whether the passed character is uppercase letter or not. It returns a non zero value(true) for uppercase otherwise zero(false).
Function tolower converts uppercase alphabets to lowercase. If passed character(c) is uppercase, it returns lowercase equivalent to c, otherwise c remain unchanged.
Functions isupper and tolower are defined in ctype.h header file.
Here is the declaration for isupper() and tolower() function.

int isupper(int c);
int tolower(int c);
/*
* C Program to change uppercase characters 
* to lowercase characters in a string using tolower function
*/
#include <stdio.h>
#include <conio.h>
#include <ctype.h>

int main(){
    char inputString[100];
    int index;
    printf("Enter a String\n");
    gets(inputString);
    for(index=0; inputString[index] != '\0'; index++){
        /* Check if character in inputArray is upper Case*/
        if(isupper(inputString[index])){
            /* Convert upper case character to lower case 
               using tolower function */
            inputString[index] = tolower(inputString[index]);
        } else {
            inputString[index] = inputString[index];
        }
    }
    inputString[index] = '\0';
    printf("String with all lowercase characters \n%s ", inputString);

    getch();
    return 0;
}
Program Output
Enter a String
C Programming Is Awesome
String with all lowercase characters 
c programming is awesome

C program to convert uppercase string to lowercase string using user defined function

Here we are using two user defined functions, isUpperCase() and toLowerCase(). isUpperCase function returns one if passed character is uppercase character otherwise zero. toLowerCase returns lowercase character corresponding to upperCase character c.


/*
* C Program to change uppercase characters 
* to lowercase characters in a string using function
*/
#include <stdio.h>
#include <conio.h>

int isUpperCase(char c);
int toLowerCase(char c);

int main(){
    char inputString[100];
    int index;
    printf("Enter a String\n");
    gets(inputString);
    for(index=0; inputString[index] != '\0'; index++){
        /* Check if character in inputArray is upper Case*/
        if(isUpperCase(inputString[index])){
            /* Convert upper case character to lower case*/
            inputString[index] = toLowerCase(inputString[index]);
        } else {
            inputString[index] = inputString[index];
        }
    }
    inputString[index] = '\0';
    printf("String with all lowercase characters \n%s", inputString);

    getch();
    return 0;
}
/*
 * Returns one if passed character is 
 * uppercase character otherwise zero
 */
int isUpperCase(char c){
    if(c >= 'A' && c <= 'Z')
        return 1;
    else 
        return 0;
}

/*
 * Returns lowercase character corresponding to uppercase
 * character c
 */
int toLowerCase(char c){
    /* Add the difference between lowercase character 
     * and it's uppercase character(for example: 'a'-'A'= 2) 
     */
    return c + (32); 
}
Program Output
Enter a String
C ProGraMMing Is AweSome
String with all lowercase characters 
c programming is awesome

Related Topics
C program to convert lowercase string to uppercase
C program to remove vowels from a string
C program to remove extra spaces from string
C Program to find frequency of characters in a string
C program to find a substring from a given string
C program to check if two strings are anagram
C program to check string is palindrome
List of all C programs