Upper To Lower
Upper To Lower
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.
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:
1 #include <stdio.h>
2 #include <string.h>
3
4 int main()
5 {
6 char s[1000];
7 int i;
8
9 printf("Enter the string : ");
10 gets(s);
11
12
13
14 for(i=0;s[i];i++)
15 {
16 if(s[i]>=65 && s[i]<=90)
17 s[i]+=32;
18 }
19
20
21 printf("string in lowercase ='%s'\n",s);
22
23
24 return 0;
25 }
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.
1 #include <stdio.h>
2 #include <string.h>
3
4 void stringlowercase(char *s)
5 {
6 int i;
7
8 for(i=0;s[i];i++)
9 {
10 if(s[i]>=65 && s[i]<=90)
11 s[i]+=32;
12 }
13
14
15
16 }
17 int main()
18 {
19
20 char s[1000];
21 int i;
22
23 printf("Enter the string: ");
24 gets(s);
25
26
27 stringlowercase(s);
28
29 printf("string in lowercase ='%s'\n",s);
30
31 }
Output:
1 #include <stdio.h>
2 #include <string.h>
3
4
5 int main()
6 {
7 char s[1000];
8
9 printf("Enter the string: ");
10 gets(s);
11
12
13 strlwr(s);
14
15 printf("string in lowercase ='%s'\n",s);
16
17 return 0;
18
19 }
Output: