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

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)

Leave a Reply Cancel reply

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

Programs

  • C Programs
  • Java Programs
  • C++ Programs

Copyright © 2012 – 2022 BeginnersBook . Privacy Policy . Sitemap