|
NAMEtrio_printf, trio_fprintf, trio_sprintf, trio_snprintf, trio_snprintfcat, trio_aprintf, trio_vprintf, trio_vfprintf, trio_vsprintf, trio_vsnprintf, trio_vaprintf - formatted output conversion SYNOPSIS
cc ... -ltrio -lm #include <trio.h> int trio_printf(const char *format, ...); DESCRIPTIONThis documentation is incomplete. The documentation of the printf family in [C99] and [UNIX98] also applies to the trio counterparts. All these functions outputs a string which is formatted according to the format string and the consecutive arguments. The format string is described in the Formatting section below. trio_printf and trio_vprintf writes the output to the standard output stream (stdout). trio_fprintf and trio_vfprintf writes the output to a given output stream. trio_dprintf and trio_vdprintf writes the output to a file descriptor (this includes, for example, sockets). trio_sprintf and trio_vsprintf writes the output into buffer. trio_snprintf and trio_vsnprintf writes max - 1 characters into buffer followed by a terminating zero character. If max is 1, then buffer will be an empty string. If max is 0, then buffer is left untouched, and can consequently be NULL. The number of characters that would have been written to buffer, had there been sufficient space, is returned. trio_snprintfcat appends the formatted text at the end of buffer. trio_asprintf and trio_vasprintf allocates and returns a string in buffer containing the formatted text. FORMATTING
The format string can contain normal text and conversion indicators. The normal text can be any character except the nil character (ASCII 000 = '0') and the percent character (ASCII 045 = '%'). Conversion indicators consists of an indication character (%), followed by zero or more conversion modifiers, and exactly one conversion specifier. NOTE: The examples below are missing the n character. This was omitted to improve readability. To make trio_printf actually print the formatted text, the n character must be added to the examples. Furthermore, the | character is used to clarify the output. MODIFIERS
Some modifiers exhibit the same behaviour for all specifiers, other modifiers indicate different behaviours for different specifiers, and other modifiers are only applicable to certain specifiers. The relationship is described for each modifier. The number 9 is used to denotes an arbitary integer.
Positional (9$) [UNIX98]
Mixing Reference Gap Double Reference
The following two statements are equivalent
1. trio_printf("|%d %s|", 42, "meanings"); 2. trio_printf("|%1$d %2$s|", 42, "meanings");
Width (9)
1. trio_printf("|%10i|", 42);
Precision (.9)
1. trio_printf("|%10.8i|%.8i|", 42, 42);
Base (..9) [TRIO]
1. trio_printf("|%10.8.2i|%10..2i|%..2i|", 42, 42, 42); 2. trio_printf("|%*.8.*i|", 10, 2, 42);
Padding (0)
Short (h)
Short short (hh) [C99, GNU]
Largest (j) [C99]
Long (l)
Long long (ll) [C99, UNIX98, GNU]
Long double (L) [C99, UNIX98, GNU]
ptrdiff_t (t) [C99]
Quad (q) [BSD, GNU]
size_t (z) [C99]
size_t (Z) [GNU]
Alternative (#)
Spacing ( )
Sign (+)
Alignment (-)
Argument (*)
Quote/Grouping (') [MISC]
Sticky (!) [TRIO]
* Integers (i, u, d, o, x, X) * Floating-point (f, F, e, E, g, G, a, A) * Characters (c, C) * Strings (s, S) * Pointer (p) * Count (n) * Errno (m) * Group ([])
The sticky modifiers are active until superseeded by other sticky modifiers, or the end of the format string is reached.
1. trio_printf("|%!08#x|%04x|%x|", 42, 42, 42);
Allocate (<alloc>) [TRIO] SPECIFIERS
Percent (%)
1. trio_printf("Percent is %%");
Hex floats (a, A) [C99]
1. trio_printf("|%a|%A|", 3.1415, 3.1415e20);
Binary numbers (b, B) [MISC - SCO UnixWare 7]
Character (c)
* Quote (') [TRIO]
Decimal (d)
* Grouping (') [TRIO]
Assuming the thousand separator is comma and the grouping is set to 3
1. trio_printf("|%'ld|", 1234567);
Floating-point (e, E)
[\-]9.99 is the mantissa (as described for the f, F specifier), e[\-]9 is the exponent indicator (either e or E, depending on the floating-point specifier), followed by an optional sign and the exponent
Floating-point (f, F)
[\-] is an optional sign (either + or -), 9 is the integer-part (possibly interspersed with thousand-separators), . is the decimal-point (depending on the locale), and 99 is the fractional-part.
The following modifiers holds a special meaning for this specifier
* Alternative (#) [C99] * Grouping (') [TRIO]
Floating-point (g, G)
Integer (i)
Errno (m) [GNU]
Count (n)
Octal (o)
Pointer (p)
* Alternative (#) [TRIO]
String (s)
* Quote (') [TRIO] * Alternative (#) [TRIO]
a (ASCII 007) = alert b (ASCII 010) = backspace f (ASCII 014) = formfeed n (ASCII 012) = newline r (ASCII 015) = carriage return t (ASCII 011) = horizontal tab v (ASCII 013) = vertical tab
1. trio_printf("|One %s Three|One %'s Three|", "Two", "Two"); 2. trio_printf("|Argument missing %s|", NULL); 3. trio_printf("|%#s|", "007 a.");
Unsigned (u)
Hex (x, X)
* Alternative (#)
RETURN VALUESAll functions returns the number of outputted characters. If an error occured then a negative error code is returned [TRIO]. Note that this is a deviation from the standard, which simply returns -1 (or EOF) and errno set appropriately. The error condition can be detected by checking whether the function returns a negative number or not, and the number can be parsed with the following macros. The error codes are primarily intended as debugging aide for the developer. Example:
int rc; rc = trio_printf("%r", 42); if (rc < 0) { if (TRIO_ERROR_CODE(rc) != TRIO_EOF) { trio_printf("Error: at position 0n", TRIO_ERROR_NAME(rc), TRIO_ERROR_POSITION(rc)); } } rc = trio_printf("%r", 42); if (rc < 0) { if (TRIO_ERROR_CODE(rc) != TRIO_EOF) { trio_printf("Error: at position 0n", TRIO_ERROR_NAME(rc), TRIO_ERROR_POSITION(rc)); } } SEE ALSOtrio_scanf (3) CONFORMING TOThroughout this document the following abbreviations have been used to indicate what standard a feature conforms to. If nothing else is indicated ANSI C (C89) is assumed.
C89 ANSI X3.159-1989 C99 ISO/IEC 9899:1999 UNIX98 The Single UNIX Specification, Version 2 BSD 4.4BSD GNU GNU libc MISC Other non-standard sources TRIO Extensions specific for this package LEGAL ISSUESCopyright (C) 1998-2000 Bjorn Reese and Daniel Stenberg. Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER. This HTML page was made with roffit. |
Web page edited by daniel at haxx.se, modified April 05, 2005