C Program to convert all Uppercase characters to lowercase and vice-versa in a string.
Here is the c program to convert all uppercase characters into lowercase characters using the ASCII values.
#include<stdio.h>
#include<conio.h>
void main()
{ char str[200];
int i=0;
clrscr();
printf(“Enter a String:”); // the ASCII value of A-Z is 65-90 and a-z is 97-122 so it is gets(str); clearly seen that the difference between lowercase and
printf(“Actual string:”); uppercase is 32
puts(str); // so by adding 32 the uppercase character is converted into
for(i=0;str[i]!=’\0′;i++) lowercase and by subtracting 32 the lowercase is
{ if(str[i]>=’A’ && str[i]<=’Z’) converted into uppercase
{ str[i]=str[i]+32;
}
else
{ str[i]=str[i]-32;
}
}
printf(“Converted String:%s”,str);
getch();
}
Output