printf.3s (2010 09)

p
printf(3S) printf(3S)
[EFBIG] An attempt was made to write to a file that exceeds the process’s file size limit or the
maximum file size (see ulimit (2)).
[EINTR] A signal was caught during the
write() system call.
[EIO] The process is in a background process group and is attempting to write to its controlling
terminal,
TOSTOP is set, the process is neither ignoring nor blocking the
SIGTTOU sig-
nal, and the process group of the process is orphaned.
[ENOSPC] There was no free space remaining on the device containing the file.
[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), standards(5),
thread_safety(5), glossary(9).
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
6 Hewlett-Packard Company 6 HP-UX 11i Version 3: September 2010