Subj : Any C programmers out there? To : Sarah Nunez From : George White Date : Thu Feb 08 2001 03:40 pm * Replying to a message in : OS2 Hi Sarah, On 06-Feb-01, Sarah Nunez wrote to All: Over in OS2 you asked: SN> Off-topic request: SN> I need someone to give me some ideas on how to make a case SN> statement respond to letters as well as numbers. (Plain vanilla SN> ANSI C.) Please contact me privately at the email address below The easy way is (extract from working code): int character; /* The character is input into a char array called 'buffer' */ character = buffer[0] | 0x20; /* Lower case ASCII characters */ if ((character >= '0') && (character <= '9')) character -= '0'; /* Numbers to 0 - 9 */ else if (character >= 'a') character -= 0x57; /* ASCII alpha to 0x0a et sequa */ else character = 0x10; /* Or other default behaviour */ /* as required by the application */ switch (character) { case 0x00: character = status_display (vdu,&buffer[1],24,FALSE); break; case 0x01: character = operational_display (vdu); break; case 0x02: /* Lost/Damaged cards */ /* etc */ break; default: ; /* Ignore anything else */ } /* End switch statement */ How does it work? First I or the character with 0x20 - this has no effect on the numbers and converts letters to lower case. Then I offset the numbers (0x30 to 0x39) to run from 0x00 otherwise I convert all lower case letters to run from 0x0A. Any other characters are converted to a default value (in my case 0x10 because I only use 0-9 and the letters a-f) if you want all the alpha characters this would be 'z' - 0x56 (I'm too lazy to work it out at this time of night). Then I have a value in 'character' which runs from 0 to my upper switch limit, and off we go :-). George --- Terminate 5.00/Pro * Origin: A country point under OS/2 (2:257/609.6) .