HP-UX Reference (11i v2 04/09) - 3 Library Functions N-Z (vol 7)
p
printf(3S) printf(3S)
[EPIPE] An attempt is made to write to a pipe or FIFO that is not open for reading by any process.
A SIGPIPE signal is also sent to the process.
[EILSEQ] The data obtained from the input stream does not form a valid wide character.
[ENOMEM] Insufficient storage space is available.
Additional
errno values can be set by the underlying
write() function (see write(2)).
EXAMPLES
To print a date and time in the form "Sunday, July 3, 10:02", where weekday and month are pointers to
null-terminated strings:
printf("%s, %s %d, %d:%.2d", weekday, month, day, hour, min);
To print Pi to 5 decimal places:
printf("Pi = %.5f", 4 * atan(1.0));
To create a language independent date-and-time printing routine write:
printf(format,weekday,month,day,hour,min,2,2);
For American usage, format would point to the string:
"%1$s, %2$s %3$d, %4$*6$.*7$d:%5$*6$.*7$d"
and result in the output:
"Sunday, July 3, 10:02"
For German usage, the string:
"%1$s, %3$s %2$d, %4$*6$.*7$d:%5$*6$.*7$d"
results in the output:
Sonntag, 3 Juli 10:02
WARNINGS
Notice that with the c conversion character, an int arg is converted to an unsigned char. Hence, whole
multibyte characters cannot be printed using a single c conversion character.
A precision with the
s conversion character might result in the truncation of a multibyte character.
Use of a conversion character which doesn’t match the type of the corresponding argument passed in will
result in invalid data being returned. For example, the modifying
ll, specifying that the following
d, i,
o, u, x,orX conversion character applies to a long long integer arg, is necessary for proper results when
the argument is a long long integer.
AUTHOR
printf(), fprintf(), and sprintf() were developed by AT&T and HP.
SEE ALSO
ecvt(3C), ltostr(3C), setlocale(3C), putc(3S), scanf(3S), stdio(3S), orientation(5), thread_safety(5).
STANDARDS CONFORMANCE
printf(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C
fprintf(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C
sprintf(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C
Section 3−−740 Hewlett-Packard Company − 5 − HP-UX 11i Version 2: September 2004