

I'd use the read procedure for the general case. lang racket (with-input-from-file 'data. In Windows, replace (read-line (current-input-port) 'any) with (read-line) and see what happens. This kind of destructuring & conversion from strings to values can sometimes be more conveniently handled by converting your source data into something that looks like Racket S-expressions (in this case, by removing the commas) and then calling read to do the rest, e.g. (char->integer (string-ref a (- (string-length a) 1)))) (printf "input: ~a, length: ~a, last character: ~a\n" (define a (read-line (current-input-port) 'any))
#Racket file peek char portable
So, 'any is required to be portable when the input port is not a file (standard input). Opened in text mode, 'linefeed is usually the appropriate read-line Return-linefeed combinations to a linefeed. Additional procedures let you open ports to strings. When you use a file for input or output, you need to explicitly open and close a port to the file (with procedures described in this chapter). ForĮxample, reading a file in text mode on Windows automatically changes The standard I/O port, console-i/o-port, is opened automatically when you start Scheme. If one of the input operations (read, read-char, or peek-char) is asked. Return and linefeed characters are detected after the conversions thatĪre automatically performed when reading a file in text mode. An input port often points to a finite stream, e.g., an input file stored on disk.

To be portable across Unix and Windows, additional option is required. For instance (regexp-match #px" *(+)" (current-input-port)) scanf does), I would suggest a regexp-match on the input. at the low level, I would suggest (read-line) and (read-bytes).

If the port is at end of file then char-ready returns. You can do pretty much everything you want to. If char-ready returns t then the next read-char operation on the given port is guaranteed not to hang.
