I am trying to convert a char element from an char *argv[] array to lowercase from uppercase without using a function. I want to add 32 to the ascii integer.
When I try
I will not point the problems that other answerers did, I will show a neat trick to perform the swap upper-lower. For the letters, the difference between the lower case and the upper case letters is the bit 5 in the ascii code. So to set the letter lowercase you need to set this bit:
lower = 0x20 | letter;
For uppercase reset the bit:
upper = (~0x20) & letter;
And to swap the case you can use XOR:
swapped = 0x20 ^ letter;
The good thing here that you don't have to worry and check whether or not the letter is already the case you need.
Of course the assumption here is that your system is using ASCII encoding.