convert uppercase to lowercase in C

In this program you will learn how you can convert string from uppercase to lowercase, In C language every character represent as a integer value known as ASCII. ASCII value of small letter (a-z) are (97-122) and capital (A-Z) are (65-90)

#include<stdio.h>
void main()
{
 char str[20];
 int i;
 printf("\n enter a string:");
 gets(str);
 for(i=0;str[i]!='\0';i++)
 {
    //it will convert uppercase to lowercase
    if(str[i]>=65 && str[i]<=90)
    {
    	str[i]=str[i]+32;
    }
 }
 printf(" %s",str);
}

output

enter a string:WELCOME TO MY WEBSITE
welcome to my website

working of uppercase to lowercase program in C

  • input string from the user, and store it some variable let say str
  • run the loop from 0 till end of string
  • When you want to change from uppercase to lowercase, you have to add the ASCII value of uppercase letters to 32. why adding it with 32 because diffrence of a-A=32
  • For example: A+32=a i.e 65+32=97
  • 65 is ASCII value of capital A and 97 is ASCII value of small a