Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages


home | help
PRINTF(3S)							    PRINTF(3S)

       printf, fprintf,	sprintf	- formatted output conversion

       #include	<stdio.h>

       printf(format [,	arg ] ...  )
       char *format;

       FILE *stream;
       char *format;

       char *sprintf(s,	format [, arg ]	...  )
       char *s,	format;

       Printf  places  output  on  the standard	output stream stdout.  Fprintf
       the string s, followed by the character `\0'.

       Each of these functions converts, formats, and prints its arguments af-
       ter the first under control of the first	argument.  The first  argument
       is  a character string which contains two types of objects: plain char-
       acters, which are simply	copied to the output  stream,  and  conversion
       specifications,	each  of  which	 causes	conversion and printing	of the
       next successive arg printf.

       Each conversion specification is	introduced by the character  %.	  Fol-
       lowing the %, there may be

       -      an  optional  minus  sign	`-' which specifies left adjustment of
	      the converted value in the indicated field;

       -      an optional digit	string specifying a field width; if  the  con-
	      verted  value  has fewer characters than the field width it will
	      field width begins with a	zero, zero-padding will	 be  done  in-
	      stead of blank-padding;

       -      an optional period `.'  which serves to separate the field width
	      from the next digit string;

       -      an optional digit	string specifying a precision which  specifies
	      printed from a string;

       -      the character l specifying that a	following d, o,	x, or u	corre-
	      sponds to	a long integer arg.  (A	 capitalized  conversion  code
	      accomplishes the same thing.)

       -      a	 character  which  indicates  the type of conversion to	be ap-

       this case an integer arg	supplies the field width or precision.

       The conversion characters and their meanings are

       dox    The  integer  arg	is converted to	decimal, octal,	or hexadecimal
	      notation respectively.

	      point is equal to	the precision specification for	the  argument.
	      If  the  precision is missing, 6 digits are given; if the	preci-
	      sion is explicitly  0,  no  digits  and  no  decimal  point  are

       e      The   float   or	 double	  arg	is   converted	in  the	 style
	      point  and the number after is equal to the precision specifica-
	      tion for the argument; when the precision	is missing,  6	digits
	      are produced.

	      style e, whichever gives full precision in minimum space.

       c      The character arg	is printed.  Null characters are ignored.

	      from  the	string are printed until a null	character or until the
	      number of	characters indicated by	the precision specification is
	      reached; however if the precision	is 0 or	missing	all characters
	      up to a null are printed.

       u      The unsigned integer arg is converted  to	 decimal  and  printed
	      (the result will be in the range 0 to 65535).

       %      Print a `%'; no argument is converted.

       the  actual  width.   Characters	 generated  by	printf	are printed by

       weekday and month are pointers to null-terminated strings:


       To print	pi to 5	decimals:


       ecvt(3),	putc(3S), scanf(3S)

       Very wide fields	(>128 characters) fail.

3rd Berkeley Distribution					    PRINTF(3S)


Want to link to this manual page? Use this URL:

home | help