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

4.3.1 Format Specifier Characters

The format specifier consists of one character from the following list, optionally preceded by a format type modifier (discussed below the table). The C format types c, n, u, and p are not supported. The format types J, S, t, and z are available in LUX but not in C.


refers to an integer (long) argument. On ouput, it is printed in decimal (base 10) notation. On input, its base is determined from the first character(s): initial 0x or 0X indicate a hexadecimal (base 16) number; otherwise initial 0 indicates an octal (base 8) number; otherwise it’s a decimal (base 10) number.


refers to an integer (long) argument in decimal (base 10) notation.


refers to an integer (long) argument in octal (base 8) notation. On input, an initial 0 is allowed.

x, X

refer to an integer (long) argument in hexadecimal (base 16) notation, using letters a through f to denote hexadecimal "digits" 10 through 15. On input, initial 0x or 0X are allowed. On output, %x requests lower-case letters, and %X requests upper-case letters.

e, E

refer to a floating-point (float, double) argument in exponential notation. Exponential notation consists of a plus sign or minus sign, some decimal digits, a decimal point (usually a period .), more decimal digits, an exponent marker, a plus sign or minus sign, and some decimal digits. The exponent marker is an e or an E. The part before the exponent marker is the mantissa, and the part after the exponent marker is the exponent. The indicated number is equal to the product of the mantissa and ten to the power of the exponent. On output, the exponent is always printed. On input, the exponent, decimal point, initial sign, and all except one digit are optional.


refers to a floating-point (float, double) argument which is printed in fixed-point notation (i.e., with a decimal point but no exponent).

g, G

refer to a floating-point (float, double) argument. On output, it is printed in exponential (%e for %g, %E for %G) notation if the exponent is less than -4 or not less than the precision; otherwise, fixed-point (%f) notation is used. On input, %g and %G work like %e. By default, a trailing decimal point and trailing zeros after the decimal point are not printed.


refers to a date and time argument. On output, the value (a float or double) is interpreted as a Chronological Julian Day Number (for %J) or a Julian Day Number (for %#j) and converted to the corresponding date in the common Western calendar; calendar for more information about calendar transformations. The specified precision determines how many components of the date and time are shown, starting from the year: %.1J provides just the year, %.2J the year and the month, %.3J the year, month, and day, %.4J through %.6J add the hour, minute, and second, and greater precisions add further sexagesimal divisions of seconds. If a width is specified that is greater than is needed for minimal output, and if left alignment is selected, then the last displayed component is shown with further digits after the decimal marker until the specified width has been filled. %.6J yields a date and time in ISO 8601 format, similar to 2000-12-30T03:04:05.

s, S

refer to a string argument. On output, both formats are equivalent. On input, the %s format does not accept whitespace (i.e., reads one whitespace-delimited word), and the %S format does accept whitespace except for newlines.


refers to a floating point (float, double) argument. On output, it is printed with the fractional part in sexagesimal notation, similar to 1234:45:56. The field width indicates the minimum width of the string and the precision the number of sexagesimal elements. The precision defaults to 2 (i.e., hh:mm) and cannot be less than 2. All elements are printed as 2-digit integers, except the last one, which is printed as a floating-point number. The string is lengthened (if necessary to attain the minimum field width) by printing the last element with more digits after the decimal point. The first element is preceded by a whitespace or a sign (depending on the sign of the argument and the presence of the + modifier). The # modifier (e.g., %#t) divides the argument by 15 before transforming from decimal to sexagesimal notation: it equates 360 degrees with 24 hours.


a complex (cfloat, cdouble) number, shown as two floating-point numbers (using a %g format, or a %f if the format specifier is %#z) of which the first one represents the real part, and the second one the imaginary part of the number. The imaginary part is always displayed with a sign, and is directly followed by an i. The specified width refers to the whole output, but the specified precision applies to each of the two components separately.

d i o x X specifiers may be directly preceded by an h to indicate a word argument rather than a long argument on input, or by a j to indicate a int64 argument. e E f g G t T z specifiers may be directly preceded by an l to indicate a double argument rather than a float argument on input.

If you use a format specifier that is not in this table, then strange things may happen.

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