C program to toggle case of a string using while loop.
C program to toggle case of a string using while loop.
#include <stdio.h>
#define MAX 100
void toggleCase(char * text);
int main()
{
char text[MAX];
printf("\n Enter any string: ");
gets(text);
printf("\n String before toggling case: %s", text);
toggleCase(text);
printf("\n String after toggling case: %s", text);
return 0;
}
void toggleCase(char * text)
{
int i = 0;
while(text[i] != '\0')
{
if(text[i]>='a' && text[i]<='z')
{
text[i] = text[i] - 32;
}
else if(text[i]>='A' && text[i]<='Z')
{
text[i] = text[i] + 32;
}
i++;
}
}
Output:
Enter any string: I love c programming
String before toggling case: I love c programming
String after toggling case: i LOVE C PROGRAMMING
Process returned 0 (0x0) execution time : 11.406 s
Enter any string: Programming
String before toggling case: Programming
String after toggling case: pROGRAMMING
Process returned 0 (0x0) execution time : 9.981 s