codescracker


c

C Program to Convert Uppercase to Lowercase



« Previous Program Next Program »


Uppercase to Lowercase Conversion in C

Here are the two programs, first is to convert uppercase character to lowercase character and the second is to convert uppercase string to lowercase string in C programming. Let's first start with, how to convert a character from uppercase to lowercase in C programming.

Uppercase Character to Lowercase in C

Let's first convert character from uppercase to lowercase, so the following C program ask to the user to enter a character in uppercase to convert it into lowercase, then display the result on the screen. Since ASCII value of A is 65 and ASCII value of a is 97. So to convert a character from uppercase to lowercase, we have to add (97-65) i.e., 32 to get the ASCII value of the character in lowercase. Then print it on the screen :

C Programming Code to Convert Uppercase Character to Lowercase

/* C Program - Convert Uppercase Character to Lowercase */
		
#include<stdio.h>
#include<conio.h>
void main()
{
	clrscr();
	char ch;
	printf("Enter a character in uppercase : ");
	scanf("%c",&ch);
	ch=ch+32;
	printf("character in lowercase = %c",ch);
	getch();
}

When the above c program is compile and executed, it will produce the following result:

c program convert uppercase character to lowercase

Convert Uppercase String to Lowercase in C

Now let's convert string from uppercase to lowercase. To convert uppercase to lowercase string, you have to ask to the user to enter the string in uppercase to convert it into lowercase to display the equivalent string in lowercase. To change uppercase string into lowercase string, just add 32 in each character of the string in uppercase to convert it into lowercase. Since ASCII value of A is 65 and ASCII value of a is 97 so 65+32 = 97 = a = equivalent value of A in lowercase i.e., a. So the following C program ask to the user to enter a string like first name in uppercase to convert it into lowercase, then display the result on the screen:

C Programming Code to Convert Uppercase String to Lowercase

/* C Program - Convert Uppercase String to Lowercase */
		
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
  clrscr();
  char str[20];
  int i;
  printf("Enter the String (Enter First Name) in uppercase : ");
  scanf("%s",str);
  for(i=0;i<=strlen(str);i++)
  {
	    if(str[i]>=65 && str[i]<=92)
	    {
		str[i]=str[i]+32;
	    }
  }
  printf("\nThe String in Lowercase = %s",str);
  getch();
}

When the above c program is compile and executed, it will produce the following result:

uppercase to lowercase conversion in c

Same Program in Other Programming Language

You may also like same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test