beginnersbook.com

  • Home
  • All Tutorials
    • Learn Servlet
    • Learn JSP
    • Learn JSTL
    • Learn C
    • Learn C++
    • Learn MongoDB
    • Learn XML
    • Learn Python
    • Learn Perl
    • Learn Kotlin
  • Core Java
  • OOPs
  • Collections
  • Java I/O
  • JSON
  • DBMS

C Program to convert uppercase string to lowercase string

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.

Enjoyed this post? Try these related posts

  1. C Program to Check whether an Alphabet is Vowel or Consonant
  2. C Program to Count Vowels and Consonants in a String using Pointer
  3. C Program to calculate Area of Equilatral triangle
  4. C Program to Find the Number of Elements in an Array
  5. C Program to Find ASCII value of a Character
  6. C Program for bubble sorting

Leave a Reply Cancel reply

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

Programs

  • C Programs
  • Java Programs

Recently Added..

  • JSON Tutorial
  • Java Regular Expressions Tutorial
  • Java Enum Tutorial
  • Java Annotations Tutorial

Copyright © 2012 – 2021 BeginnersBook . Privacy Policy . Sitemap