As we know that every character on the keyboard has a unique ASCII Value for Capital Alphabet (Upper Case) and Small Alphabet(Lower Case) so converting any case to any case (lower case to upper case and upper case to lower case). We have to remember the number 32 cause this is a number for converting any string into any case.
We have to just add the number 32 or minus the number 32 from each character of the string and we solved our conversion problem. I strongly recommend checking the ASCII program in C. So in this problem, we are just comparing if the number is less than the lower case ASCII number change to convert it into the upper case or vice versa.
C Program to Convert Uppercase Letters to Lowercase and Vice Versa
#include <stdio.h>
#include <string.h>
void main()
{
/*C Program to Convert Lowercase to Uppercase And Vice Versa */
printf("=======================================");
printf("\nVisit - www.programmingwithbasics.com");
printf("\n=====================================");
while (1)
{
char str[20];
int i;
printf("\n\nEnter The String: ");
scanf("%s", str);
for (i = 0; i <= strlen(str); i++)
{
if (str[i] >= 65 && str[i] <= 90)
{
str[i] = str[i] + 32;
}
else if (str[i] >= 97 && str[i] <= 122)
{
str[i] = str[i] - 32;
}
}
printf("\n\nConvert String(Convert Lowercase to Uppercase) Is: %s\n\n", str);
}
return 0;
}
0 Comments: