How to compare ASCII char with octal number

Discussion in 'Apple' started by Peter, Nov 5, 2007.

  1. Peter

    Peter Guest

    Hi,

    In the function below i select a random ASCII character (A-Z) which
    must be pressed by a user.
    The ASCII character is generated by printing a character in octal
    notation. I need to compare
    the key pressed by the end-user with the character represented by the
    octal number. Therefore
    i convert the octal number to a character using the print
    instruction ;

    uorg=`print "\0${randoctkey}"`

    Is there a better/nicer way to do this ?

    warnandwait() {

    print "\nTHINK! Incorrect use of this tool can stop all
    communications."
    typeset -i i=0
    while ((i <= 2));
    do
    print -n ".";
    (( i = i + 1));
    sleep 1
    done
    # generate random octal number in decimal 65-90
    randoctkey=`echo "obase=8;$((RANDOM%(90-65+1)+65))"| bc`
    print "\nPress the \"\0${randoctkey}\" key to continue"

    uresp=`getch`
    uorg=`print "\0${randoctkey}"`

    if [[ $uorg != $uresp ]]
    then
    print "If even pressing the right key is a challenge,"
    print "consider NOT using this script."
    exit 1
    fi

    }
     
    Peter, Nov 5, 2007
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.