BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

C Program to convert uppercase string to lowercase string

Last Updated: February 10, 2015 by Chaitanya Singh | Filed Under: C Programs

In the following C program, user would be asked to enter a String (it can be in complete uppercase or partial uppercase) and then the program would convert it into a complete(all characters in lower case) lower case string. The logic we have used in the following program is: All the upper case characters (A-Z) have ASCII value ranging from 65 to 90 and their corresponding lower case characters (a-z) have ASCII value 32 greater than them. For example ‘A‘ has a ASCII value 65 and ‘a‘ has a ASCII value 97 (65+32). Same applies for 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;
}

Output:

uppercase_to_lowercase_string_output
As you can see in the output that we have entered a partial (only few chars were in upper case) upper case string and the program output was a complete lower case string.

Top Related Articles:

  1. C Program for bubble sorting
  2. C Program to concatenate two strings without using strcat
  3. C Program to find greatest of three numbers
  4. C Program to Multiply two Floating Point Numbers
  5. C Program to swap first and last elements of an array

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

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

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap