While "all the world runs ASCII", to abuse the saying, I would respectfully recommend a more portable method of converting alphabetic characters to indices. Something like the following would work:
Code:
int aindex(char c)
{
const char ab[] = "abcdefghijklmnopqrstuvwxyz";
char *p = strchr(ab, tolower((unsigned char)c));
if(p != NULL)
{
return p - ab;
}
return -1;
}
Or it might be faster (does it matter?) to use a switch:
Code:
int aindex(char c)
{
switch(tolower((unsigned char)c))
{
case 'a': return 0; case 'b': return 1; case 'c': return 2; case 'd': return 3;
case 'e': return 4; case 'f': return 5; case 'g': return 6; case 'h': return 7;
case 'i': return 8; case 'j': return 9; case 'k': return 10; case 'l': return 11;
case 'm': return 12; case 'n': return 13; case 'o': return 14; case 'p': return 15;
case 'q': return 16; case 'r': return 17; case 's': return 18; case 't': return 19;
case 'u': return 20; case 'v': return 21; case 'w': return 22; case 'x': return 23;
case 'y': return 24; case 'z': return 25;
}
return -1;
}
I suppose this is a rather quixotic quest (especially when UTF-8 has the same values as ASCII for a-z and A-Z), but I think I'll continue to tilt at the windmills that represent portability.