.TH PRINTN 3F .UC .SH NAME printn, fprntn, sprntn \- formatted output conversion .SH SYNTAX .B character*(L) format .br .B call printn(format .RB [ , arg ] ... .B ) .PP .B integer fileid .br .B character*(L) format .br .B call fprntn(fileid, format .RB [ , arg ] ... .B ) .SM .PP .B character*(L) s, sprntn, format .br .B s = sprntn(format .RB [ , arg ] ... .B ) .SH DESCRIPTION .I Printn places output on the standard output. .I Fprntn places output on the file associated with .I fileid (see .IR open (3F)). .I Sprntn returns `output' as its function value. .PP Each of these functions converts, formats, and prints its arguments after the .I format under control of the .I format argument. The .I format argument is a character string which contains two types of objects: plain characters, which are simply copied to the output, and conversion specifications, each of which causes conversion and printing of the next successive argument. .PP Each conversion specification is introduced by the character .BR % . Following the .BR % , there may be: .TP \- an optional minus sign `\-' which specifies .I "left adjustment" of the converted value in the indicated field; .TP \- an optional digit string .B m , specifying a .I "field width," .I "iteration count," or .I "array size;" if the converted value 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 begins with a zero, zero-padding will be done instead of blank-padding; .TP \- an optional period .RB ` . ' which serves to separate the field width from the next digit string; .TP \- an optional digit string specifying a .I precision which specifies the number of digits to appear after the decimal point, for e- and f-conversion, or the maximum number of characters to be printed from a string; .TP \- the character .B l specifying that a following .BR d , .BR o , or .BR x , corresponds to an .B integer*4 .I argument. (A capitalized conversion code accomplishes the same thing.) .TP \- a character which indicates the type of conversion to be applied. .PP A field width or precision may be `*' and an iteration count or array size may be `^' instead of a digit string. In these cases an .B integer*2 .I arg supplies the value used. .PP The conversion characters and their meanings are .TP .B dox The integer .I arg is converted to decimal, octal, or hexadecimal notation respectively. .TP .B n (Equivalent to .BR 'ld' ). The .B integer*4 .I arg is converted to decimal notation. .TP .B f The .B real or .B double .B precision .I arg is converted to decimal notation in the style `[\fB\-\fP]ddd.ddd' where the number of d's after the decimal point is equal to the precision specification for the argument. If the precision is missing, 6 digits are given; if the precision is explicitly 0, no digits and no decimal point are printed. .TP .B e The .B real or .B double .B precision .I arg is converted in the style `[\fB\-\fP]d\fB.\fPddd\fBe\fP\(+-dd' where there is one digit before the decimal point and the number after is equal to the precision specification for the argument; when the precision is missing, 6 digits are produced. .TP .B g The .B real or .B double precision .I arg is printed in style .BR d , in style .BR f , or in style .BR e , whichever gives full precision in minimum space. .TP .B c The character .I arg is printed. Null characters are ignored. .TP .B s .I arg is taken to be a string 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 is 0 or missing all characters up to a null are printed. .TP .B a Take the next argument to be an array of dimension .BR m . No argument is converted. .TP .B ( Begin loop: .B n is used as the number of iterations. If .B m is omitted, the last .B m is used. No argument is converted. .TP .B { Begin loop and take the next argument to be an array. .RB '% m {' is equivalent to .RB '% m a% m ('. .B m is used as both the iteration count and the array dimension. No argument is converted. .TP .B ) End of loop. No argument is converted. .TP .B } Same as ')'. .TP .B % Print a `%'; no argument is converted. .PP In no case does a non-existent 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 .I printn are printed by .IR putc (3F). .SH EXAMPLES To print a date and time in the form `Sunday, July 3, 10:02', where .I weekday and .I month are null-terminated strings: .RS .HP .nh printn('%s, %s %d, %02d:%02d', weekday, month, day, hour, min); .RE .hy .PP To print .if n pi .if t \(*p to 5 decimals: .IP printn('pi = %.5f', 4*atan(1.0)); .SH "SEE ALSO" putc(3F), scann(3F) .SH BUGS Very wide fields (>128 characters) fail. .SH AUTHOR James Herriot and Bruce Julian, U.S. Geological Survey, Menlo Park, California