28/02/2023

C Program to Convert Lowercase to Uppercase And Vice Versa

Write a program in c to read a sentence and replace lowercase characters with uppercase and vice-versa or Lower case to upper case in C or How to convert a given string into lowercase and uppercase without using library functions in C or C program to change the case of a string conversion (Lower to Upper) or C Program to Convert Lowercase to Uppercase And Vice Versa

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.

C Program to Convert Lowercase to Uppercase And Vice Versa

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

The Output of Convert Lowercase to Uppercase


The Output of Convert Lowercase to Uppercase

Similar to Convert Lowercase to Uppercase


Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

0 Comments: