As for C, you cannot rely on an ASCII executable; the standard establishes only the minimum set of characters that should belong to it. The execution character set can be ASCII, it can be EBCDIC, it can be UTF-8, etc.
Your method is "safe" in the sense that it should not call segfault or open a security hole, but it does not guarantee the return of the expected result.
For the Latin alphabet, you better create your own string and index it:
char mycharset[] = "abcdefghijklmnopqrstuvwxyz"; if ( isalpha( letter )) // thanks chux. { char *pos = strchr( mycharset, tolower( letter ) ); if ( pos ) return (int) (pos - mycharset); else return -1; // letter not found } return -1; // bad input
For extended alphabets - I don't know.
source share