Toggle case of all characters of string
C program to toggle case of all characters of string. i.e. to convert upper case characters to lower case characters and lower case characters to upper case characters in a string.
Program
#include<stdio.h>
#include<conio.h>
#define MAX 50
void main()
{
char str[MAX];
int i;
printf("Enter the string\t:");
gets(str);
i = 0;
while(str[i] != '\0')
{
if(str[i]>=65 && str[i]<=92)
str[i] = str[i] + 32;
else if(str[i]>=97 && str[i]<=122)
str[i] = str[i] - 32;
i++;
}
printf("\nString in toggled case is\t:%s",str);
getch();
}
Output
Enter the string :Welcome to CourseCRUX.com
String in toggled case is :wELCOME TO cOURSEcrux.COM