Next: , Previous: , Up: Input/Output   [Contents][Index]

4.3 Formatted Input/Output

The format in which output is printed may be specified in various ways, which broadly divide into two classes: those that find a format suitable for the argument, and those that map the argument to fit the format. The first class is used by routine type and its aliases, as well as by printf, string, and str. The second class is used by fprint, fprintf, and fstring.

Input routines are similarly divided into two classes. Routines read and readf read data depending on the argument type, and routines fread, freadf, and freads read data according to a specified format.

To do any kind of formatted input or output, one must be able to specify the format that is to be used. LUX uses format specifications which are modeled on those from C, but with some modifications.

Format strings consist of ordinary text, format entries, and format groupings. All format entries are introduced by a percent sign (%) and must contain a specifier character (which indicates the type of data the format applies to). The simplest formats contain nothing more.

A general single format entry consists of the following components, in the indicated order:

  1. a percent sign (%)
  2. optional modifier characters (Format Modifiers)
  3. an optional field width (an unsigned integer number) (Format Field Width)
  4. an optional period (.)
  5. an optional precision (an unsigned integer number) (Format Precision)
  6. an optional type modifier character (Format Specifiers)
  7. a format specifier character (Format Specifiers)
  8. an optional repeat count followed by a pound sign (#)
  9. optional plain text

See also: fprint, fprintf, fread, freadf, freads, fstring, printf, read, readf, str, string, type.

Next: , Previous: , Up: Input/Output   [Contents][Index]