Changes

Functions HI-TECH C PRINTF

3,386 bytes added, 22:51, 31 July 2017
Created page with "<strong>PRINTF, VPRINTF</strong> ==SYNOPSIS== #include <stdio.h> int printf(char * fmt, ...) int vprintf(char * fmt, va_list va_arg) ==DESCRIPTION== <strong>Printf</s..."
<strong>PRINTF, VPRINTF</strong>
==SYNOPSIS==

#include <stdio.h>

int printf(char * fmt, ...)
int vprintf(char * fmt, va_list va_arg)


==DESCRIPTION==
<strong>Printf</strong>() is a formatted output routine, operating on
stdout. There are corresponding routines operating on a
given stream (<strong>fprintf</strong>()) or into a string buffer
(<strong>sprintf</strong>()). <strong>Printf</strong>() is passed a format string, followed by a list of zero or more arguments. In the format string are conversion specifications, each of which
is used to print out one of the argument list values.
Each conversion specification is of the form %m.nc
where the percent symbol % introduces a conversion,
followed by an optional width specification m. n is an
optional precision specification (introduced by the
dot) and c is a letter specifying the type of the
conversion. A minus sign ('-') preceding m indicates
left rather than right adjustment of the converted
value in the field. Where the field width is larger
than required for the conversion, blank padding is performed at the left or right as specified. Where right
adjustment of a numeric conversion is specified, and
the first digit of m is 0, then padding will be performed with zeroes rather than blanks.

If the character * is used in place of a decimal constant, e.g. in the format %*d, then one integer argument will be taken from the list to provide that value.
The types of conversion are:

;f
:Floating point - m is the total width and n is the number of digits after the decimal point. If n is omitted it defaults to 6.

;e
:Print the corresponding argument in scientific notation. Otherwise similar to f.

;g
:Use e or f format, whichever gives maximum precision in minimum width.

;o x X u d
:Integer conversion - in radices 8, 16, 10 and 10 respectively. The conversion is signed in the case of d, unsigned otherwise. The precision value is the total number of digits to print, and may be used to force leading zeroes. E.g. %8.4x will print at least 4 hex digits in an 8 wide field. Preceding the key letter with an l indicates that the value argument is a long integer or unsigned value. The letter X prints out hexadecimal numbers using the upper case letters <strong>A-F</strong> rather than <strong>a-f</strong> as would be printed when using x.

;s
:Print a string - the value argument is assumed to be a character pointer. At most n characters from the string will be printed, in a field m characters wide.

;c
:The argument is assumed to be a single character and is printed literally.

Any other characters used as conversion specifications
will be printed. Thus %% will produce a single percent
sign. Some examples:

printf("Total = %4d%%", 23)
yields 'Total =23%'
printf("Size is %lx" , size)
where size is a long, prints size
as hexadecimal.
printf("Name = %.8s", "a1234567890")
yields 'Name = a1234567'
printf("xx%*d", 3, 4)
yields 'xx 4'


Printf returns EOF on error, 0 otherwise. <strong>Vprintf</strong>() is
similar to <strong>printf</strong>() but takes a variable argument list
pointer rather than a list of arguments. See the
description of <strong>va_start</strong>() for more information on variable argument lists.

==SEE ALSO==

fprintf, sprintf