int position = 'g' - 'a' + 1;
In C, char
values are convertible to int
values and take on their ASCII values. In this case, 'a'
is the same as 97 and 'g'
is 103. Since the alphabet is contiguous within the ASCII character set, subtracting 'a'
from your value gives its relative position. Add 1 if you consider 'a'
to be the first (instead of zeroth) position.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…