Returning the ASCII value of character from an input channel

inchar()

Return ASCII value of character from an input channel


SYNTAX

inchar(channel)

The inchar function returns the ASCII value of the next character from channel.

If channel is zero, this refers to the keyboard, and the function is identical to keycode(0). If the key pressed corresponds to one of the “Sent by” sequences defined in the terminal parameter file, inchar(0) returns a negative number. A standard set of related manifest constants is defined in $SCULPTOR/include/keycode.h. Otherwise the ASCII code for the character is returned as a positive number. See keycode(0) for full details.

If channel is greater than zero, then the channel must previously have been opened with the open # command. If an error, such as end of file, is encountered, the function returns the value -1.

The inchar function, unlike get # or put # , does not recognise the separator character.

This function returns an integer. Since this can be a negative value, it should be stored in an i2 field or larger.


NOTES

  • The channel number must fall within the range 0-64.

  • All characters are input. The inchar function makes no distinction between separator characters and other characters.


EXAMPLE

!temp Asc,,i2
!temp Chr,,a1

     open #1, "/usr/fred/example.txt" read
     tmp.Asc = inchar(1)
     if (tmp.Asc = -1) then goto CLOSE_FILE   /* error, probably end of file */
     tmp.Chr = chr(tmp.Asc)

CLOSE_FILE:
     close #1
     end

RELATED TOPICS

Terminal parameter files

keycode(0)

The include file <keycode.h>

Sequential files