I'm making a program that, if the user inputs a lowercase character, generates its character in uppercase, and the opposite too. I'm using a function in order convert the character into lowercase or uppercase based on the ASCII table. Lowercase to uppercase is being converted correctly, but uppercase to lowercase is not.
char changeCapitalization(char n) { //uppercase to lowercase if(n>=65 && n<=90) n=n+32; //lowercase to uppercase if(n>= 97 && n<=122) n=n-32; return n; }
(n>='a' && n<='z' || n>='A' && n<= 'Z' ? n ^ 0x20 : n).