Beginners Programs :

C Program To Convert Uppercase String To Lowercase | 4 Ways

C program to convert an uppercase string to lowercase – In this article, we will brief in on the multiple ways to convert an uppercase string to lowercase in C programming.

Suitable examples and sample programs have also been added so that you can understand the whole thing very clearly. The compiler has also been added with which you can execute it yourself.

In this piece, the ways used are as follows:

  • Using Standard Method
  • Using Function
  • Using Recursion
  • Using String Library Function

A string is nothing but an array of characters. The value of a string is determined by the terminating character. Its value is considered to be 0.

C Program To Convert Uppercase String To Lowercase

As you can see in the image uploaded above, firstly, we need to enter a particular string in uppercase which we want to convert to lowercase.

The string entered here is: HELLO

Hence, the lowercase string, in this case, will be: hello

Thus, the different methods to convert a specific uppercase string to lowercase are as follows:

Using Standard Method

  1. Read the entered string which is in the upper case using gets(s) function.

2) The upper case alphabets ASCII value range is from 65 to 90.

3) For loop iterates with the structure for(i=0;s[i];i++)

If the ASCII value of any character of the string is in the range between 65 to 90,

Add 32 to the ASCII value of the character to convert into lower case.

4) After all iterations of for loop, we will get the string with lowercase alphabets.

Output:

Using Function

  1. The main() calls the stringlowercase() function to convert the uppercase alphabets of the string to lower case alphabets.

2) The stringlowercase() function checks each characters ASCII value of the given string. If any character’s ASCII value is in the range between 65 to 90 then add  32 to the ASCII value of the character. Then the character will be converted to lower case. Like this, the function converts all uppercase characters into lowercase.

3) Print the string which is having all lower case alphabets.

Output:

Using Recursion

  1. The main() calls the stringlowercase() function by passing the string as an argument.

2) If character available then stringlowercase() function checks the ASCII value of s[i] is in between 65 to 90 then add 32 to ASCII value of the character and the lower case character will be placed into s[i++]. The function calls itself by passing modified string s. It calls recursively until if (s[i]) becomes false.i.e there is no characters for checks.

3) Print the lower case string.

Output:

Using String Library Function
  1. The main() calls the library function strlwr(s) by passing the string as an argument.

2) The library function strlwr() which converts upper case string into the lowercase string.The strlwr() function is available at ‘string.h’ header file.

Output: