uppercase check function

i was reading the documentation about specifieing templates when i discovered a function about uppercase chars. i didnt get anything of it. can someone please explain me what theyre doing here.

code:
1
2
3
4
5
6
char uppercase ()
    {
      if ((element>='a')&&(element<='z')) // i think this is to make sure the char is one of the alphabet
      element+='A'-'a'; // element=element + 'A'-'a' ??
      return element; //i know this
    }

the element char was already initialized above
first you must understand ascii. characters are just numbers: http://www.asciitable.com/

if ((element>='a')&&(element<='z'))

this checks the character "element" whether it is lower case. (see ascii table)
When it is lower case a number is added to make ik Upper case.

'A' = 65
'a' = 97

so -32 (65 - 97) is added to the element when it is lower case.

example:

element = 'v'
so element is also 118

-32 is added to the 118, this results in 86.
ascii 86 is the same as 'V'.

and the new element is returned.
Last edited on
so the whole thing would resulted the same when they should have written:
element-=32; instead of element+='A'-'a';
yes your right
thanks
Topic archived. No new replies allowed.