text: Toggle case of a string using Bitwise Operators | C program to get toggle case of a string ; tOGGLE cASE = swaps CAPS to lower case and lower case to CAPS ; Bitwise EXOR with 32 ; Driver Code
code: #include <stdio.h> NEW_LINE char * toggleCase ( char * a ) { for ( int i = 0 ; a [ i ] != ' \0' ; i ++ ) { a [ i ] ^= 32 ; } return a ; } int main ( ) { char str [ ] = " CheRrY " ; printf ( " Toggle ▁ case : ▁ % s STRNEWLINE " , toggleCase ( str ) ) ; printf ( " Original ▁ string : ▁ % s " , toggleCase ( str ) ) ; return 0 ; }