• Any C programmers out there?

    From George White@2:257/609.6 to Sarah Nunez on Thu Feb 8 15:40:57 2001
    * Replying to a message in : OS2

    Hi Sarah,

    On 06-Feb-01, Sarah Nunez wrote to All:

    Over in OS2 you asked:

    Off-topic request:

    I need someone to give me some ideas on how to make a case
    statement respond to letters as well as numbers. (Plain vanilla
    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 */
    if (character >= 'a')
    character -= 0x57; /* ASCII alpha to 0x0a et sequa */
    character = 0x10; /* Or other default behaviour */
    /* as required by the application */
    switch (character)
    case 0x00:
    character = status_display (vdu,&buffer[1],24,FALSE);
    case 0x01:
    character = operational_display (vdu);
    case 0x02: /* Lost/Damaged cards */
    /* etc */
    ; /* 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 :-).


    --- Terminate 5.00/Pro
    * Origin: A country point under OS/2 (2:257/609.6)