C

C Program For Converting Uppercase To Lowercase Strings

The user would be asked to enter a String (complete or partial uppercase) in the following C program, and the program would convert it to a complete (all characters in lower case) lower case string. The logic we used in the following program is as follows: All upper case letters (A-Z) have ASCII values ranging from 65 to 90, while their corresponding lower case letters (a-z) have ASCII values 32 higher. For example, the ASCII value of ‘A’ is 65, and the ASCII value of ‘a’ is 97 (65+32). The same is true for the other characters.

/* C program to convert uppercase string to
 * lower case
 * written by: Chaitanya
 */
#include<stdio.h>
#include<string.h>
int main(){
   /* This array can hold a string of upto 25
    * chars, if you are going to enter larger string
    * then increase the array size accordingly
    */
   char str[25];
   int i;
   printf("Enter the string: ");
   scanf("%s",str);
 
   for(i=0;i<=strlen(str);i++){
      if(str[i]>=65&&str[i]<=90)
         str[i]=str[i]+32;
   }
   printf("\nLower Case String is: %s",str);
   return 0;
}

As seen in the output, we entered a partial (only a few characters were in upper case) upper case string, and the program output was a complete lower case string.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button