API Reference › Builtin functions › read_char
function

read_char

read_char() -> int

Reads a single byte from standard input and returns its value, or -1 when the input has ended. It is the foundation for headless, pipe-driven runs: a test or tool can feed the program a stream of bytes and process them one at a time, looping until read_char returns -1. Compare the byte against character literals such as 'a' to interpret it. It takes no arguments and advances through the input on each call.

Example

program CountInputBytes {
  handler DrainInput phase Start {
    var byte_count: int = 0
    var next_byte = read_char()
    while next_byte != -1 {
      byte_count = byte_count + 1
      next_byte = read_char()
    }
    print(byte_count)
  }
}
← All symbols