1.0 Formatted output conversion _________ ______ __________ ********** * printf * ********** NAME: printf -- Formatted output conversion SYNOPSIS: printf(format, arg1, ...) char *format; fprintf(stream, format, arg1, ...) FILE *stream; char *format; char * sprintf(buffer, format, arg1, ...); char *buffer; char *format; c_doprnt(format, argvec, iov) char *format; int *argvec[]; FILE *stream; Description printf() converts, formats, and prints its arguments, under control of the first argument, writing output to stdout. fprintf() writes its output to the indicated file. sprintf() writes its output to the indicated string buffer. c_doprnt() is the internal print formatter which is called by printf, etc. sprintf() returns a pointer to the EOS at the end of the output buffer. This is not necessarily transportable. The format argument is a character string which contains two types of objects: plain characters, which are simply copied to the output stream, and conversion specifications, each of which causes conversion and printing of the next successive argument to printf. Each conversion specification is introduced by the character %. Following the %, there may be - an optional minus sign "-" which specifies left adjustment of the converted argument in the Page 2 printf Formatted output conversion indicated field. - an optional digit string specifying field width. If the converted argument has fewer characters than the field width, it will be blank-padded on the left (or right, if the left-adjustment indicator has been given) to make up the field width. If the field width is specified as '*' or '?', the next argument is used. (Note: '?' is obsolete.) If the width is specified with a leading zero, zeros are used for padding instead of blanks. This zero does NOT imply an octal field width. For example, assume the value 123 is to be printed: %d "123" %5d " 123" %-5d "123 " %05d "00123" - an optional period "." which serves to separate the field width from the precision argument. - an optional digit string (precision) which specifies the number of digits to be printed from a string. If the precision is specified as '*' or '?', the next argument is used. If the precision is zero, no bytes in the string will be printed. - a character which indicates the type of conversion to be applied. The conversion characters and their meanings are b Binary (bits) d Signed-decimal u Unsigned-decimal o Octal x Hexadecimal, 10-15 are represented by a-f The integer argument is converted to decimal, octal, or hexadecimal notation respectively. Any of the conversion characters may be capitalized or preceeded by 'l' to signal "long" integer argument. c The argument character is printed. If the argument is zero (EOS), it will be ignored. q The (16-bit) integer is printed as a pair of octal bytes in the format "123.456" The bytes follow the PDP-11 order (high order byte first). This format is not transportable to other systems. r Remote format. The next printf() argument is the format. Note that this is not a subroutine. The current format is not processed further. For Page 3 printf Formatted output conversion example: bug(args) { error("Error at %r", &args); } This routine might be called as follows: bug("Error %d at %s\n", val, name); %r is not transportable to all implementations of the standard library. It does not word on Vax-11 C, for example. c_prnt() may be used as shown below for similar functionality. s The argument is taken to be a string (character pointer) and characters 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 specification is 0 or missing all characters up to null are printed. If no recognizable character appears after the %, that character is printed; thus % may be printed by the use of the string %%. In no case does a non-existant or small field width cause truncation of a field; padding takes place only if the specified field width exceeds the actual width. Characters generated by printf() are printed by calling putchar(). c_prnt() is the internal print formatter called by all "top-level" print functions. It is functionally identical to the Unix and Vax-11 C _doprnt() library routine. Unfortunately, the leading '_' conflicts with RSX-11M file services library routine conventions, requiring the use of an unique prefix. If your programs wish to call c_prnt, a potentially transportable procedure would be: #ifdef decus c_prnt(format, args, iov); #else _doprnt(format, args, iov); #endif You should assume, however, that _doprnt() is not necessarily present on all implementations of the "standard library." BUGS: