C

C Program For Converting Lowercase To Uppercase Strings

The user would be asked to enter a lower case String in the following program, and the program would convert it to an upper case String. The program’s logic was as follows: Lower case characters (a to z) have ASCII values ranging from 97 to 122, while upper case characters (A to Z) have ASCII values 32 less. For example, ‘a’ has an ASCII value of 97, while ‘A’ has an ASCII value of 65. (97-32). The same is true for other alphabets. Based on this logic, we created the C program shown below for conversion.

Converting a String from lowercase to uppercase in C

/* 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;
}

As seen in the screenshot above, we entered a lower case string (beginnersbook.com) and the program converted it to an upper case string (BEGINNERSBOOK.COM).

Related Articles

Leave a Reply

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

Back to top button