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 lowercase string to uppercase string

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

In the following program, user would be asked to enter a lower case String and the program would convert it into a Upper case String. Logic followed in the program: All lower case characters (a to z) have ASCII values ranging from 97 to 122 and their corresponding upper case characters (A to Z) have ASCII values 32 less than them. For example ‘a’ has a ASCII value 97 and ‘A’ has a ASCII value 65 (97-32). Same applies for other alphabets. Based on this logic we have written the below C program for conversion.

C program – Conversion of a String from lowercase to uppercase

 
/* C Program to convert Lower case
 * String to Upper case.
 * Written by: Chaitanya
 */

#include<stdio.h>
#include<string.h>
int main(){
   char str[25];
   int i;

   printf("Enter the string:");
   scanf("%s",str);

   for(i=0;i<=strlen(str);i++){
      if(str[i]>=97&&str[i]<=122)
         str[i]=str[i]-32;
   }
   printf("\nUpper Case String is: %s",str);
   return 0;
}

Output:

lowercase_to_uppercase_output
As you can observe in the above screenshot, we have entered a lower case string(beginnersbook.com) and the program converted into a Upper case string (BEGINNERSBOOK.COM)

Top Related Articles:

  1. C Program for bubble sorting
  2. C Program to concatenate two strings without using strcat
  3. C Program to Multiply two Floating Point Numbers
  4. C program to replace first occurrence of vowel with ‘-‘ in string
  5. C Program to Access Array Elements Using Pointer

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