Functions HI-TECH C PRINTF
#include <stdio.h> int printf(char * fmt, ...) int vprintf(char * fmt, va_list va_arg)
Printf() is a formatted output routine, operating on stdout. There are corresponding routines operating on a given stream (fprintf()) or into a string buffer (sprintf()). Printf() 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:
- 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.
- Print the corresponding argument in scientific notation. Otherwise similar to f.
- 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 A-F rather than a-f as would be printed when using x.
- 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.
- 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. Vprintf() is similar to printf() but takes a variable argument list pointer rather than a list of arguments. See the description of va_start() for more information on variable argument lists.