Here is my code(Tested).
Note:
You have to substract 32 if you want to change the char form lover to upper case and have to add 32 to that character for upper to lower case.
As ASCII value of A = 65 and Z = 90 and a = 97 and z = 127, and their difference is 32 i.e (a - A) or (z - Z).
#include <stdio.h>
int main()
{
char str[10] = "My SpAce";
int i;
printf("String before change : %s\n", str);
for (i = 0; str[i]; i++) {
if (str[i] != ' ') {
if (str[i] >= 'a' && str[i] <= 'z') {
str[i] -= 32;
} else if (str[i] >= 'A' && str[i] <= 'Z') {
str[i] += 32;
}
}
}
printf("String After change : %s\n", str);
return 0;
}