C Program to replace all lowercase vowels into uppercase in a string

Here is the C program to convert lowercase characters into uppercase and vice-versa.
#include<stdio.h>
#include<conio.h>
 
void main()
{         char str[200];
           int i=0;
           clrscr();
           printf(“Enter a String:”);
           gets(str);
           printf(“Actual string:”);
           puts(str);
           for(i=0;str[i]!=’\0′;i++)
          {         if(str[i]>=’A’ && str[i]<=’Z’)
                    {          str[i]=str[i]+32;
                     }
                     else
                    {           str[i]=str[i]-32;
                     }
           }
           printf(“Converted String:%s”,str);
           getch();
}
 
Output
Logic of program
  • The characters in lowercase can be converted into uppercase by using the logic of ASCII value.
  • The ASCII value of lower characters(a-z) is 97-122 respectively and uppercase character(A-Z) is 65-90 respectively.
  • So here it is clearly seen the difference in ASCII values of lowercase and uppercase characters is 32.
  • So if the 32 is subtracted from the ASCII value of lowercase character than it can be converted into uppercase character and vice-versa.
  • The loop used i.e for loop which will go to every single character of the string starting from i=0 to the null character(‘\0’).
  • If-else is used for making a condition that if the character in a string is lowercase than it will follow the condition written in it and will convert it to uppercase and vice-versa.
 

You may also like...

Leave a Reply