Hi skawt05,
Each character in the collating sequence is actually stored as a sort of integer (which may differ between implementations). If you try
int i = 'A';
you will be able to find out which one actually stores 'A' on your machine, for example.
In the ASCII character set (and many/most others - but not all: see below) these characters are in successive sequence. So 'B' is 1 more than 'A', 'C' is 2 more than 'A', 'D' is 3 more than 'A'. Thus, if you did
'B' - 'A'
in such a sequence you would get 1. Similarly,
'C' - 'A'
would produce 2 ... and so on. If you want to get 1, 2, 3 ... for 'A', 'B', 'C' then you will have to correct by adding 1. Thus
IF your character series is in successive order then
(alpha[w] - 'A' + 1)
would number the upper case letters from 1 to 26. Note that the lower-case letters, however, are quite a long way from the upper-case ones.
The problem, as @JLBorges pointed out right at the start, is that you can't guarantee that the characters are in successive order like this - it may depend on your locale or the machine's collating sequence. If you want a notorious example see
https://en.wikipedia.org/wiki/EBCDIC#Criticism_and_humor
and note that this was devised by IBM!
So the answer is ... on most English/American PCs this code will map the upper case alphabet to the numbers 1-26 ... it's just that you can't rely on that fact.
The later codes in this thread try to map the alphabet directly to numbers (taking into account case on the way) and lessen the portability issues.