C Program to Convert String to Upper Case, Lower Case and Toggle Case

C Program to Convert String to Upper Case, Lower Case and Toggle Case

Write C Program to Convert String to Upper Case, Lower Case and Toggle Case

// C Program to Convert String to Upper Case, Lower Case and Toggle Case

#include <stdio.h>
#include <string.h>

int main()
{
	char S[100] = "Hello and Welcome To Codecrucks";

	int i=0;
	printf("Original String :--> %s", S);

	printf("\n\nUpper Case :--> ");
	while(S[i] != '\0')     //TO CONVERT INTO THE UPPER CASE
	{
	    if(S[i] >= 'a' && S[i] <= 'z')
                printf("%c", S[i] - 32);
            else
                printf("%c", S[i]);
		i++;
	}

	i = 0;
	printf("\nLower Case :--> ");
	while(S[i] != '\0')     //TO CONVERT INTO THE UPPER CASE
	{
	    if(S[i] >= 'A' && S[i] <= 'Z')
                printf("%c", S[i] + 32);
            else
                printf("%c", S[i]);
	    i++;
	}

        i = 0;
	printf("\nToggle Case :--> ");
	while(S[i] != '\0')     //TO CONVERT INTO THE UPPER CASE
	{
             if(S[i] >= 'A' && S[i] <= 'Z')
                printf("%c", S[i] + 32);
            else if(S[i] >= 'a' && S[i] <= 'z')
                printf("%c", S[i] - 32);
            else
                printf("%c", S[i]);
	    i++;
	}
	return 0;
}

Output:

Original String :--> Hello and Welcome To Codecrucks

Upper Case :--> HELLO AND WELCOME TO CODECRUCKS
Lower Case :--> hello and welcome to codecrucks
Toggle Case :--> hELLO AND wELCOME tO cODECRUCKS