EBCDIC is apparently still used in IBM mainframes, although ASCII is "tolerated" in that you can edit ascii files and the cpu has instructions for conversion. EBCDIC - Wikipedia
I would use int since character literals are ints in C anyway, and functions like getchar return an int.
Code:
#include <stdio.h>
#include <ctype.h>
int get_index(int ch)
{
ch = toupper(ch);
if (ch >= 'A' && ch <= 'I') return ch - 'A';
if (ch >= 'J' && ch <= 'R') return ch - 'J' + 9;
if (ch >= 'S' && ch <= 'Z') return ch - 'S' + 18;
return -1;
}
int main()
{
int ch;
while ((ch = getchar()) != EOF)
printf("%d\n", get_index(ch));
return 0;
}
A switch might actually be faster.
Code:
int get_index(int ch)
{
switch (toupper(ch))
{
case 'A': return 0;
case 'B': return 1;
}
return -1;
}