printf_s(3c) 맨 페이지 - 윈디하나의 솔라나라

개요

섹션
맨 페이지 이름
검색(S)

printf_s(3c)

printf(3C)               Standard C Library Functions               printf(3C)

NAME
       printf,   fprintf,  dprintf,  sprintf,  snprintf,  asprintf,  printf_s,
       fprintf_s, sprintf_s, snprintf_s - print formatted output

SYNOPSIS
       #include <stdio.h>

       int printf(const char *restrict format, ...);


       int fprintf(FILE *restrict stream, const char *restrict format, ...);


       int dprintf(int fildes, const char *restrict format, ...);


       int sprintf(char *restrict s, const char *restrict format, ...);


       int snprintf(char *restrict s, size_t n,
            const char *restrict format, ...);


       int asprintf(char **ret, const char *restrict format, ...);


       #define __STDC_WANT_LIB_EXT1__ 1
       #include <stdio.h>

       int printf_s(const char *restrict format, ...);


       int fprintf_s(FILE *restrict stream, const char *restrict format, ...);


       int sprintf_s(char *restrict s, rsize_t n,
            const char *restrict format, ...);


       int snprintf_s(char *restrict s, rsize_t n,
            const char *restrict format, ...);

DESCRIPTION
       The printf() function places output on the standard output stream  std‐
       out.


       The fprintf() function places output on the named output stream stream.


       The  dprintf()  function  places output on the file associated with the
       file descriptor fildes rather than on a stream.


       The sprintf() function places output, followed by the null  byte  (\0),
       in  consecutive bytes starting at s; it is the user's responsibility to
       ensure that enough storage is available.


       The snprintf() function is identical to sprintf() with the addition  of
       the argument n, which specifies the maximum number of bytes to write to
       the buffer referred to by s. If n is 0, nothing is written and s can be
       a  null pointer. Otherwise, output bytes beyond the n-1st are discarded
       instead of being written to the array and a null byte is written at the
       end of the bytes actually written into the array.


       The asprintf() function is the same as the  sprintf()  function  except
       that  it  returns,  in the ret argument, a pointer to a newly allocated
       buffer sufficiently large to  hold  the  output  string.  This  pointer
       should  be  passed to free(3C) to release the allocated storage when it
       is no longer needed. If sufficient space cannot be allocated,  the  as‐
       printf() function returns -1 and sets ret to be a NULL pointer.


       Each of these functions converts, formats, and prints its arguments un‐
       der  control of the format. The format is a character string, beginning
       and ending in its initial shift state, if any. The format  is  composed
       of  zero  or  more  directives:  ordinary  characters, which are simply
       copied to the output stream  and  conversion  specifications,  each  of
       which  results  in  the fetching of zero or more arguments. The results
       are undefined if there are insufficient arguments for  the  format.  If
       the  format  is  exhausted while arguments remain, the excess arguments
       are evaluated but are otherwise ignored.


       Conversions can be applied to the nth argument after the format in  the
       argument  list,  rather than to the next unused argument. In this case,
       the conversion specifier % (see below) is replaced by the sequence %n$,
       where n is a decimal integer in the range [1,  NL_ARGMAX],  giving  the
       position  of  the  argument in the argument list. This feature provides
       for the definition of format strings that select arguments in an  order
       appropriate to specific languages (see the EXAMPLES section).


       In format strings containing the %n$ form of conversion specifications,
       numbered arguments in the argument list can be referenced from the for‐
       mat string as many times as required.


       In  format  strings containing the % form of conversion specifications,
       each argument in the argument list is used exactly once.


       All forms of the printf() functions allow for the insertion of  a  lan‐
       guage-dependent radix character in the output string. The radix charac‐
       ter  is  defined  by the program's locale (category LC_NUMERIC). In the
       POSIX locale, or in a locale where the radix character is not  defined,
       the radix character defaults to a period (.).

   Conversion Specifications
       Each  conversion  specification  is introduced by the % character or by
       the character sequence %n$, after which the  following  appear  in  se‐
       quence:

           o      An optional field, consisting of a decimal digit string fol‐
                  lowed  by a $, specifying the next argument to be converted.
                  If this field is not provided, the args following  the  last
                  argument converted will be used.


           o      Zero  or more flags (in any order), which modify the meaning
                  of the conversion specification.


           o      An optional minimum field width. If the converted value  has
                  fewer  bytes  than  the  field width, it will be padded with
                  spaces by default on the left; it  will  be  padded  on  the
                  right,  if the left-adjustment flag (‐), described below, is
                  given to the field width. The field width takes the form  of
                  an asterisk (*), described below, or a decimal integer.

                  If  the conversion specifier is s, a standard-conforming ap‐
                  plication (see standards(7)) interprets the field  width  as
                  the  minimum  number  of bytes to be printed; an application
                  that is not standard-conforming interprets the  field  width
                  as  the  minimum number of columns of screen display. For an
                  application that is not standard-conforming, %10s  means  if
                  the  converted  value  has  a  screen  width of 7 columns, 3
                  spaces would be padded on the right.

                  If the format is %ws, then the field width should be  inter‐
                  preted as the minimum number of columns of screen display.


           o      An  optional precision that gives the minimum number of dig‐
                  its to appear for the d, i, o, u, x, and X conversions  (the
                  field is padded with leading zeros); the number of digits to
                  appear  after the radix character for the a, A, e, E, f, and
                  F conversions, the maximum number of significant digits  for
                  the  g  and G conversions; or the maximum number of bytes to
                  be printed from a string in s and S conversions. The  preci‐
                  sion  takes  the  form of a period (.) followed either by an
                  asterisk (*), described below, or an optional decimal  digit
                  string, where a null digit string is treated as 0. If a pre‐
                  cision  appears with any other conversion specifier, the be‐
                  havior is undefined.

                  If the conversion specifier is s or S, a standard-conforming
                  application (see standards(7)) interprets the  precision  as
                  the  maximum  number  of bytes to be written; an application
                  that is not standard-conforming interprets the precision  as
                  the  maximum number of columns of screen display. For an ap‐
                  plication that is not standard-conforming, %.5s would  print
                  only  the  portion  of  the  string  that would display in 5
                  screen columns. Only complete characters are written.

                  For %ws, the precision should be interpreted as the  maximum
                  number of columns of screen display. The precision takes the
                  form  of  a period (.) followed by a decimal digit string; a
                  null digit string is treated as zero. Padding  specified  by
                  the  precision  overrides the padding specified by the field
                  width.


           o      An optional length modifier that specified the size  of  the
                  argument.


           o      A conversion specifier that indicates the type of conversion
                  to be applied.



       A  field  width,  or precision, or both can be indicated by an asterisk
       (*). In this case, an argument of type int supplies the field width  or
       precision. Arguments specifying field width, or precision, or both must
       appear  in  that  order before the argument, if any, to be converted. A
       negative field width is taken as a − flag followed by a positive  field
       width.  A negative precision is taken as if the precision were omitted.
       In format strings containing the %n$ form of  a  conversion  specifica‐
       tion,  a field width or precision may be indicated by the sequence *m$,
       where m is a decimal integer in the range [1, NL_ARGMAX] giving the po‐
       sition in the argument list (after the format argument) of  an  integer
       argument containing the field width or precision, for example:

         printf("%1$d:%2$.*3$d:%4$.*3$d\n", hour, min, precision, sec);



       The  format  can  contain either numbered argument specifications (that
       is, %n$ and *m$), or unnumbered argument specifications (that is, % and
       *), but normally not both. The only exception to this is that %% can be
       mixed with the %n$ form. The results of mixing numbered and  unnumbered
       argument specifications in a format string are undefined. When numbered
       argument  specifications are used, specifying the Nth argument requires
       that all the leading arguments, from the  first  to  the  (N−1)th,  are
       specified in the format string.

   Flag Characters
       The flag characters and their meanings are:

       '        The integer portion of the result of a decimal conversion (%i,
                %d,  %u,  %f, %F, %g, or %G) will be formatted with thousands'
                grouping characters. For other conversions the behavior is un‐
                defined. The non-monetary grouping character is used.


       −        The result of the conversion will be left-justified within the
                field. The conversion will be right-justified if this flag  is
                not specified.


       +        The  result  of  a  signed conversion will always begin with a
                sign (+ or −). The conversion will begin with a sign only when
                a negative value is converted if this flag is not specified.


       space    If the first character of a signed conversion is not a sign or
                if a signed conversion results in no characters, a space  will
                be  placed before the result. This means that if the space and
                '+' flags both appear, the space flag will be ignored.


       #        The value is to be converted to an alternate form. For  c,  d,
                i, s, and u conversions, the flag has no effect. For an o con‐
                version,  it  increases  the precision (if necessary) to force
                the first digit of the result to be a zero. For x or X conver‐
                sion, a non-zero result will have 0x (or 0X) prepended to  it.
                For  a,  A,  e, E, f, F, g, and G conversions, the result will
                always contain a radix character, even if no digits follow the
                radix character. Without this flag, the  radix  character  ap‐
                pears  in the result of these conversions only if a digit fol‐
                lows it. For g and G conversions, trailing zeros will  not  be
                removed from the result as they normally are.


       0        For  d, i, o, u, x, X, a, A, e, E, f, F, g, and G conversions,
                leading zeros (following any indication of sign or  base)  are
                used to pad to the field width; no space padding is performed.
                If  the 0 and − flags both appear, the 0 flag will be ignored.
                For d, i, o, u, x, and X conversions, if a precision is speci‐
                fied, the 0 flag will be ignored. If the 0 and  '  flags  both
                appear,  the  grouping  characters  are  inserted  before zero
                padding. For other conversions, the behavior is undefined.


   Length Modifiers
       The length modifiers and their meanings are:

       hh              Specifies that a following d, i, o, u, x, or X  conver‐
                       sion  specifier  applies  to  a signed char or unsigned
                       char argument (the argument will have been promoted ac‐
                       cording to the integer promotions, but its  value  will
                       be  converted  to  signed  char or unsigned char before
                       printing); or that a following n  conversion  specifier
                       applies to a pointer to a signed char argument.


       h               Specifies  that a following d, i, o, u, x, or X conver‐
                       sion specifier applies to a short or unsigned short ar‐
                       gument (the argument will have been promoted  according
                       to  the  integer promotions, but its value will be con‐
                       verted to short or unsigned short before printing);  or
                       that  a  following  n conversion specifier applies to a
                       pointer to a short argument.


       l (ell)         Specifies that a following d, i, o, u, x, or X  conver‐
                       sion specifier applies to a long or unsigned long argu‐
                       ment;  that  a following n conversion specifier applies
                       to a pointer to a long argument;  that  a  following  c
                       conversion specifier applies to a wint_t argument; that
                       a following s conversion specifier applies to a pointer
                       to  a wchar_t argument; or has no effect on a following
                       a, A, e, E, f, F, g, or G conversion specifier.


       ll (ell-ell)    Specifies that a following d, i, o, u, x, or X  conver‐
                       sion  specifier applies to a long long or unsigned long
                       long argument; or that a following n conversion  speci‐
                       fier applies to a pointer to a long long argument.


       j               Specifies  that a following d, i, o, u, x, or X conver‐
                       sion specifier applies to an intmax_t or uintmax_t  ar‐
                       gument;  or that a following n conversion specifier ap‐
                       plies to a pointer to an intmax_t argument. See NOTES.


       z               Specifies that a following d, i, o, u, x, or X  conver‐
                       sion specifier applies to a size_t or the corresponding
                       signed  integer  type  argument;  or that a following n
                       conversion specifier applies to a pointer to  a  signed
                       integer type corresponding to size_t argument.


       t               Specifies  that a following d, i, o, u, x, or X conver‐
                       sion specifier applies to a  ptrdiff_t  or  the  corre‐
                       sponding  unsigned type argument; or that a following n
                       conversion  specifier  applies  to  a  pointer   to   a
                       ptrdiff_t argument.


       L               Specifies  that  a  following a, A, e, E, f, F, g, or G
                       conversion specifier applies to a long double argument.



       If a length modifier appears with any conversion specifier  other  than
       as specified above, the behavior is undefined.

   Conversion Specifiers
       Each  conversion  specifier results in fetching zero or more arguments.
       The results are undefined if there are insufficient arguments  for  the
       format.  If  the format is exhausted while arguments remain, the excess
       arguments are ignored.


       The conversion specifiers and their meanings are:

       d, i    The int argument is converted to a signed decimal in the  style
               [−]dddd.  The  precision specifies the minimum number of digits
               to appear; if the value being converted can be  represented  in
               fewer  digits,  it will be expanded with leading zeros. The de‐
               fault precision is 1. The result of converting 0  with  an  ex‐
               plicit precision of 0 is no characters.


       o       The unsigned int argument is converted to unsigned octal format
               in  the  style dddd. The precision specifies the minimum number
               of digits to appear; if the value being converted can be repre‐
               sented in fewer digits, it will be expanded with leading zeros.
               The default precision is 1. The result of converting 0 with  an
               explicit precision of 0 is no characters.


       u       The unsigned int argument is converted to unsigned decimal for‐
               mat in the style dddd. The precision specifies the minimum num‐
               ber  of  digits  to appear; if the value being converted can be
               represented in fewer digits, it will be expanded  with  leading
               zeros.  The  default precision is 1. The result of converting 0
               with an explicit precision of 0 is no characters.


       x       The unsigned int argument is converted to unsigned  hexadecimal
               format in the style dddd; the letters abcdef are used. The pre‐
               cision specifies the minimum number of digits to appear; if the
               value  being  converted  can be represented in fewer digits, it
               will be expanded with leading zeros. The default  precision  is
               1.  The  result of converting 0 with an explicit precision of 0
               is no characters.


       X       Behaves the same as the x conversion specifier except that let‐
               ters ABCDEF are used instead of abcdef.


       f, F    The double argument is converted to  decimal  notation  in  the
               style  [−]ddd.ddd,  where  the number of digits after the radix
               character (see setlocale(3C)) is equal to the precision  speci‐
               fication.  If the precision is missing it is taken as 6; if the
               precision is explicitly 0 and the # flag is not  specified,  no
               radix character appears. If a radix character appears, at least
               1  digit  appears  before it. The converted value is rounded to
               fit the specified output format  according  to  the  prevailing
               floating-point  rounding  direction  mode. If the conversion is
               not exact, an inexact exception is raised.

               For the f specifier, a double argument representing an infinity
               or NaN is converted in the style of the e conversion specifier,
               except that for an infinite argument, "infinity" or  "Infinity"
               is  printed when the precision is at least 8 and "inf" or "Inf"
               is printed otherwise.

               For the F specifier, a double argument representing an infinity
               or NaN is converted in the SUSv3  style  of  the  E  conversion
               specifier,  except that for an infinite argument, "INFINITY" is
               printed when the precision is  at  least  8  and  or  "INF"  is
               printed otherwise.


       e, E    The  double  argument  is  converted to the style [−]d.ddde±dd,
               where there is one digit before the radix character  (which  is
               non-zero  if the argument is non-zero) and the number of digits
               after it is equal to the precision. When the precision is miss‐
               ing it is taken as 6; if the precision is 0 and the #  flag  is
               not  specified,  no  radix  character appears. The E conversion
               specifier will produce a number with E instead of e introducing
               the exponent. The exponent always contains at least two digits.
               The converted value is rounded to fit the specified output for‐
               mat according to the prevailing floating-point rounding  direc‐
               tion mode. If the conversion is not exact, an inexact exception
               is raised.

               Infinity  and  NaN  values  are handled in one of the following
               ways:

               SUSv3      For the e specifier, a double argument  representing
                          an  infinity  is  printed as "[−]infinity", when the
                          precision for the conversion is at least  7  and  as
                          "[−]inf" otherwise. A double argument representing a
                          NaN  is  printed  as  "[−]nan". For the E specifier,
                          "INF", "INFINITY", and "NAN" are printed instead  of
                          "inf", "infinity", and "nan", respectively. Printing
                          of the sign follows the rules described above.


               Default    A   double  argument  representing  an  infinity  is
                          printed as "[−]Infinity", when the precision for the
                          conversion is at least 7 and as "[−]Inf"  otherwise.
                          A  double  argument representing a NaN is printed as
                          "[−]NaN". Printing of the sign follows the rules de‐
                          scribed above.



       g, G    The double argument is printed in style f or e (or in  style  E
               in  the  case  of a G conversion specifier), with the precision
               specifying the number of significant  digits.  If  an  explicit
               precision is 0, it is taken as 1. The style used depends on the
               value  converted: style e (or E) will be used only if the expo‐
               nent resulting from the conversion is less than −4  or  greater
               than or equal to the precision. Trailing zeros are removed from
               the  fractional  part  of the result. A radix character appears
               only if it is followed by a digit.

               A double argument representing an infinity or NaN is  converted
               in  the  style  of the e or E conversion specifier, except that
               for an infinite argument, "infinity", "INFINITY", or "Infinity"
               is printed when the precision is at least 8 and  "inf",  "INF",
               or "Inf" is printed otherwise.


       a, A    A  double argument representing a floating-point number is con‐
               verted in the style "[-]0xh.hhhhp±d", where the single hexadec‐
               imal digit preceding the radix point is 0  if  the  value  con‐
               verted  is  zero  and 1 otherwise and the number of hexadecimal
               digits after it is equal to the precision; if the precision  is
               missing,  the number of digits printed after the radix point is
               13 for the conversion of a double value, 16 for the  conversion
               of  a  long double value on x86, and 28 for the conversion of a
               long double value on SPARC; if the precision is  zero  and  the
               '#'  flag is not specified, no decimal-point character will ap‐
               pear. The letters "abcdef" are used for a  conversion  and  the
               letters  "ABCDEF"  for A conversion. The A conversion specifier
               produces a number with 'X' and 'P' instead of 'x' and 'p'.  The
               exponent  will  always  contain at least one digit, and only as
               many more digits as necessary to represent the decimal exponent
               of 2. If the value is zero, the exponent is zero.

               The converted value is rounded to fit the specified output for‐
               mat according to the prevailing floating-point rounding  direc‐
               tion mode. If the conversion is not exact, an inexact exception
               is raised.

               A  double argument representing an infinity or NaN is converted
               in the SUSv3 style of an e or E conversion specifier.


       c       The int argument is converted to an unsigned char, and the  re‐
               sulting byte is printed.

               If an l (ell) qualifier is present, the wint_t argument is con‐
               verted  as  if by an ls conversion specification with no preci‐
               sion and an argument that points to a two-element array of type
               wchar_t, the first element of which contains the  wint_t  argu‐
               ment  to the ls conversion specification and the second element
               contains a null wide-character.


       C       Same as lc.


       wc      The int argument is converted to a  wide  character  (wchar_t),
               and the resulting wide character is printed.


       s       The  argument must be a pointer to an array of char. Bytes from
               the array are written up to (but not including) any terminating
               null byte. If a precision is specified,  a  standard-conforming
               application  (see  standards(7))  will write only the number of
               bytes specified by precision; an application that is not  stan‐
               dard-conforming  will write only the portion of the string that
               will display in the number of columns of screen display  speci‐
               fied  by  precision.  If  the precision is not specified, it is
               taken to be infinite, so all bytes up to the  first  null  byte
               are printed. An argument with a null value will yield undefined
               results.

               If  an  l  (ell)  qualifier  is present, the argument must be a
               pointer to an array of type wchar_t. Wide-characters  from  the
               array  are converted to characters (each as if by a call to the
               wcrtomb(3C) function, with the conversion state described by an
               mbstate_t object initialized to zero  before  the  first  wide-
               character  is converted) up to and including a terminating null
               wide-character. The resulting characters are written up to (but
               not including) the terminating null  character  (byte).  If  no
               precision  is  specified,  the  array must contain a null wide-
               character. If a precision is specified, no more than that  many
               characters  (bytes)  are written (including shift sequences, if
               any), and the array must contain a null wide-character  if,  to
               equal the character sequence length given by the precision, the
               function would need to access a wide-character one past the end
               of the array. In no case is a partial character written.


       S       Same as ls.


       ws      The  argument  must  be a pointer to an array of wchar_t. Bytes
               from the array are written up to (but not including) any termi‐
               nating null character. If the precision is specified, only that
               portion of the wide-character array that will  display  in  the
               number of columns of screen display specified by precision will
               be  written.  If the precision is not specified, it is taken to
               be infinite, so all wide characters up to the first null  char‐
               acter are printed. An argument with a null value will yield un‐
               defined results.


       p       The  argument  must  be  a  pointer  to  void. The value of the
               pointer is converted to a set of sequences of printable charac‐
               ters, which should be the same as the set of sequences that are
               matched by the %p conversion of the scanf(3C) function.


       n       The argument must be a pointer to  an  integer  into  which  is
               written  the number of bytes written to the output standard I/O
               stream so far by this call to one of the printf() functions. No
               argument is converted.


       %       Print a %; no argument  is  converted.  The  entire  conversion
               specification must be %%.



       The  <inttypes.h> header defines some macros for convenient portability
       between different architectures and platforms. For printf() specifiers,
       the names of the macros is "PRI", followed by the conversion  specifier
       letter and then the datatype size. For example, PRId32 is the macro for
       the printf d conversion specifier with the flags for a 32 bit datatype.
       For more information and a full list of macros, see inttypes.h(3HEAD).


       If  a  conversion  specification does not match one of the above forms,
       the behavior is undefined.


       In no case does a non-existent or small field width cause truncation of
       a field; if the result of a conversion is wider than the  field  width,
       the  field is simply expanded to contain the conversion result. Charac‐
       ters generated by printf() and fprintf() are printed as if the putc(3C)
       function had been called.


       The st_ctime and st_mtime fields of the file will be marked for  update
       between the call to a successful execution of printf() or fprintf() and
       the next successful completion of a call to fflush(3C) or fclose(3C) on
       the same stream, or a call to exit(3C) or abort(3C), or upon successful
       completion of a call to dprintf().

   C11 Bounds Checking Interfaces
       The  printf_s(),  fprintf_s(),  sprintf_s(), and snprintf_s() functions
       are part of the C11 bounds checking interfaces  specified  in  the  C11
       standard,  Annex K. Each provide similar functionality to the printf(),
       fprintf(), sprintf(), and snprintf() functions respectively, except for
       additional checks on the parameters passed  and  explicit  runtime-con‐
       straints  as  defined  in the C11 standard. See runtime_constraint_han‐
       dler(3C) and INCITS/ISO/IEC 9899:2011.

RETURN VALUES
       Upon  successful  completion,  the  printf(),  printf_s(),   fprintf(),
       fprintf_s(),  dprintf(),  sprintf(),  sprintf_s(), and asprintf() func‐
       tions return the number of bytes  written  (excluding  the  terminating
       null byte in the case of sprintf(), sprintf_s(), and asprintf()).


       Upon  successful  completion, the snprintf() and snprintf_s() functions
       return the number of bytes that would have been written to s if  n  had
       been  sufficiently  large (excluding the terminating null byte). If the
       value of n is 0 on a call to snprintf(), s can be a  null  pointer  and
       the  number  of bytes that would have been written if n had been suffi‐
       ciently large (excluding the terminating null byte) is returned.


       The printf(), fprintf(),  dprintf(),  sprintf(),  snprintf(),  and  as‐
       printf() functions each return a negative value if an error was encoun‐
       tered, and set errno to indicate the error.


       The  printf_s()  and fprintf_s() functions each return a negative value
       if an output error, encoding error, or runtime constraint violation was
       encountered.


       The sprintf_s() function returns a negative value if an encoding  error
       is  encountered,  otherwise, it returns zero for any other runtime con‐
       straint violation.


       The snprintf_s() function returns a negative value if  a  runtime  con‐
       straint violation was encountered.

ERRORS
       For conditions under which printf(), fprintf(), and dprintf() will fail
       and may fail, refer to fputc(3C) or fputwc(3C).


       The snprintf() and snprintf_s() functions will fail if:

       EOVERFLOW    The  value  of  n is greater than INT_MAX or the number of
                    bytes needed to hold the output excluding the  terminating
                    null is greater than INT_MAX.



       The printf(), printf_s(), fprintf(), fprintf_s(), dprintf(), sprintf(),
       sprintf_s(), snprintf() and snprintf_s() functions will fail if:

       EILSEQ       A  wide-character code that does not correspond to a valid
                    character has been detected.


       EINVAL       There are insufficient arguments.


       EOVERFLOW    The value to be returned is greater than INT_MAX.



       The dprintf() function will fail if:

       EBADF    The fildes argument is not a valid file descriptor.



       The printf_s(), fprintf_s(), sprintf_s(),  and  snprintf_s()  functions
       will fail if:

       EINVAL    Null pointer is passed


       ERANGE    size argument is not a valid value



       The  printf(),  printf_s(),  fprintf(), fprintf_s(), dprintf(), and as‐
       printf() functions may fail due to an underlying malloc(3C) failure if:

       EAGAIN    Storage space is temporarily unavailable.


       ENOMEM    Insufficient storage space is available.


USAGE
       If the application calling the printf() functions has  any  objects  of
       type  wint_t  or  wchar_t, it must also include the header <wchar.h> to
       have these objects defined.

   Escape Character Sequences
       It is common to use the following escape sequences  built  into  the  C
       language  when  entering format strings for the printf() functions, but
       these sequences are processed by the C compiler, not  by  the  printf()
       function.

       \a     Alert. Ring the bell.


       \b     Backspace.  Move  the  printing position to one character before
              the current position, unless the current position is  the  start
              of a line.


       \f     Form  feed.  Move  the printing position to the initial printing
              position of the next logical page.


       \n     Newline. Move the printing position to the  start  of  the  next
              line.


       \r     Carriage  return. Move the printing position to the start of the
              current line.


       \t     Horizontal tab. Move the printing position to the next implemen‐
              tation-defined horizontal tab position on the current line.


       \v     Vertical tab. Move the printing position to  the  start  of  the
              next implementation-defined vertical tab position.



       In addition, the C language supports character sequences of the form


       \octal-number


       and


       \hex-number


       which  translates  into the character represented by the octal or hexa‐
       decimal number. For example, if ASCII representations are  being  used,
       the  letter 'a' may be written as '\141' and 'Z' as '\132'. This syntax
       is most frequently used to represent the null character as  '\0'.  This
       is  exactly  equivalent to the numeric constant zero (0). Note that the
       octal number does not include the zero prefix as it would for a  normal
       octal  constant. To specify a hexadecimal number, omit the zero so that
       the prefix is an 'x' (uppercase 'X' is not allowed  in  this  context).
       Support  for  hexadecimal  sequences  is  an  ANSI extension. See stan‐
       dards(7).

EXAMPLES
       Example 1



       The following statement prints the language-independent date  and  time
       format:


         printf (format, weekday, month, day, hour, min);




       For American usage, format could be a pointer to the string:


         "%s, %s %d, %d:%.2d\n"




       producing the message:


         Sunday, July 3, 10:02




       whereas for German usage, format could be a pointer to the string:


         "%1$s, %3$d. %2$s, %4$d:%5$.2d\n"




       producing the message:


         Sonntag, 3. Juli, 10:02


       Example 2



       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 %i, %d:%.2d", weekday, month, day, hour, min);


       Example 3



       Print pi to 5 decimal places:


         printf("pi = %.5f", 4 * atan(1.0));


       Example 4



       The following example applies only to applications that are  not  stan‐
       dard-conforming. To print a list of names in columns which are 20 char‐
       acters wide:


         printf("%20s%20s%20s", lastname, firstname, middlename);


ATTRIBUTES
       See attributes(7) for descriptions of the following attributes:

       tab()  box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) ATTRIBUTE TYPEAT‐
       TRIBUTE VALUE _ CSIEnabled _ Interface StabilityCommitted _ MT-LevelSee
       below.  _ StandardSee below.


   MT-Level
       The printf(), fprintf(),  dprintf(),  sprintf(),  snprintf(),  and  as‐
       printf() functions can be used safely in multithreaded applications, as
       long  as  setlocale(3C)  is  not being called to change the locale. The
       sprintf() and snprintf() functions are Async-Signal-Safe.


       The printf_s(), fprintf_s(),  sprintf_s(),  and  sprintf_s()  functions
       cannot be used safely in a multithreaded application due to the runtime
       constraint   handler.   For  more  information,  see  the  runtime_con‐
       straint_handler(3C) man page.

   Standard
       See standards(7) for descriptions of the following standards:

       tab() box; cw(2.2i) |cw(3.3i) lw(2.2i)  |lw(3.3i)  INTERFACESAPPLICABLE
       STANDARDS _ printf(), fprintf(), sprintf()T{
         C89 through C11,
         POSIX.1-1990 through 2008,
         SUS through SUSv4,
         XPG1 through XPG7

       T} _ snprintf()T{
         C99 through C11
         POSIX.1-2001 through 2008,
         SUSv2 through SUSv4,
         XPG5 through XPG7

       T}   _   dprintf()POSIX.1-2008,  XPG7  _  T{  printf_s(),  fprintf_s(),
       sprintf_s(), snprintf_s() T}C11 Annex K



       The asprintf() function is modeled on  the  one  that  appears  in  the
       FreeBSD, NetBSD, and GNU C libraries.

SEE ALSO
       exit(2), lseek(2), write(2), abort(3C), ecvt(3C), exit(3C), fclose(3C),
       fflush(3C), fputwc(3C), free(3C), malloc(3C), putc(3C), scanf(3C), set‐
       locale(3C),  stdio(3C),  vprintf(3C),  vwprintf(3C),  wcstombs(3C), wc‐
       tomb(3C), wprintf(3C), wsprintf(3C), inttypes.h(3HEAD),  attributes(7),
       environ(7), standards(7), runtime_constraint_handler(3C)

NOTES
       If  the  j  length modifier is used, 32-bit applications that were com‐
       piled using c89 on releases prior to Solaris 10 will  experience  unde‐
       fined behavior.

HISTORY
       The  dprintf(),  printf_s(), fprintf_s(), sprintf_s(), and snprintf_s()
       functions were added to Oracle Solaris in Oracle Solaris 11.4.0.


       The %s conversion specifier was changed to print  the  string  "(null)"
       for NULL pointer arguments in Oracle Solaris 11.0.0 and a patch for So‐
       laris 10. Prior to this, use of a NULL pointer argument would lead to a
       segmentation  fault or bus error in the program. This behavior is not a
       Committed interface, is not portable, and should not be relied on.


       The asprintf() function was added to Oracle Solaris in  Oracle  Solaris
       10 8/11 (Update 10).


       Support  for  the  length modifiers hh, j, t, and z; and the conversion
       specifiers %a, %A, and %F; was added to Solaris in the Solaris 10  3/05
       release in support of the C99 and XPG6 standards.


       The  snprintf()  return  value when n = 0 was changed in the Solaris 10
       release. The change was based on the SUSv3 specification. The  previous
       behavior was based on the initial SUSv2 specification, where snprintf()
       when n = 0 returns an unspecified value less than 1.


       The  snprintf() function was added to Solaris in Solaris 2.5, and back‐
       ported to patches for Solaris 2.3 & 2.4.


       Support for the flag character ', and the conversion  specifiers  %C  &
       %S,  was  added to Solaris in the Solaris 2.4 release in support of the
       XPG4 standard.


       Support for the length modifier ll, and the conversion  specifiers  %wc
       and %ws, was added to Solaris in the Solaris 2.0 release.


       Support for the conversion specifier %p, the length modifier L, and the
       use  of  $  to  specify argument numbers was added in the SunOS 4.1 re‐
       lease.


       The printf(), fprintf(), and sprintf() functions have been included  in
       all Sun and Oracle releases of Solaris.

Oracle Solaris 11.4               29 Jul 2021                       printf(3C)
맨 페이지 내용의 저작권은 맨 페이지 작성자에게 있습니다.
RSS ATOM XHTML 5 CSS3