Write Menu Driven C Program to Convert String Cases
// Menu Driven C Program to Convert String Cases
#include <stdio.h>
int main()
{
char S[100] = "Hello and Welcome to CodeCrucks";
int n;
do
{
printf("\n\n1.Convert String to Upper Case");
printf("\n2.Convert String to Lower Case");
printf("\n3.Convert String to Toggle Case");
printf("\n0.Exit");
printf("\n\nEnter Your Choice :--> ");
scanf("%d", &n);
printf("\nOriginal String :--> %s", S);
if(n == 1)
{
printf("\nUpper Case :--> ");
int i = 0;
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++;
}
}
else if(n == 2)
{
printf("\nLower Case :--> ");
int i = 0;
while(S[i] != '\0') //TO CONVERT INTO THE LOWER CASE
{
if(S[i] >= 'A' && S[i] <= 'Z')
printf("%c", S[i] + 32);
else
printf("%c", S[i]);
i++;
}
}
else if(n == 3)
{
printf("\nToggle Case :--> ");
int i = 0;
while(S[i] != '\0')
{
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++;
}
}
else
{
if(n==0)
{
break;
}
printf("\nPlease Enter a valid option\n");
}
}
while(n!=0);
{
printf("Thank you very much..");
}
return 0;
}
Output:
1.Convert String to Upper Case
2.Convert String to Lower Case
3.Convert String to Toggle Case
0.Exit
Enter Your Choice :--> 1
Original String :--> Hello and Welcome to CodeCrucks
Upper Case :--> HELLO AND WELCOME TO CODECRUCKS
1.Convert String to Upper Case
2.Convert String to Lower Case
3.Convert String to Toggle Case
0.Exit
Enter Your Choice :--> 2
Original String :--> Hello and Welcome to CodeCrucks
Lower Case :--> hello and welcome to codecrucks
1.Convert String to Upper Case
2.Convert String to Lower Case
3.Convert String to Toggle Case
0.Exit
Enter Your Choice :--> 3
Original String :--> Hello and Welcome to CodeCrucks
Toggle Case :--> hELLO AND wELCOME TO cODEcRUCKS
1.Convert String to Upper Case
2.Convert String to Lower Case
3.Convert String to Toggle Case
0.Exit
Enter Your Choice :--> 0