📄 printf.3s
字号:
.TH PRINTF 3S .SH NAMEprintf, fprintf, sprintf \- formatted output conversion.SH SYNOPSIS.B #include <stdio.h>.PP.B printf(format.RB [ ,arg ] ....B ).br.B char *format;.PP.B fprintf(stream, format.RB [ ,arg ] ....B ).br.SM.B FILE.B *stream;.br.B char *format;.PP.B sprintf(s, format.RB [ ,arg ] ....B ).br.B char *s, format;.SH DESCRIPTION.I Printfplaces output on the standard output stream.IR stdout ..I Fprintfplaces output on the named output.IR stream ..I Sprintfplaces `output' in the string.I s,followed by the character `\\0'..PPEach of these functions converts, formats, and prints its arguments after the firstunder control of the first argument.The first argument is a character stringwhich containstwo types of objects:plain characters, which are simply copied to theoutput stream,and conversion specifications,each of which causes conversion and printingof the next successive.I arg.IR printf ..PPEach conversion specification is introduced bythe character.BR % .Following the.BR % ,there may be.TP\-an optional minus sign `\-' which specifies.I "left adjustment"of the converted valuein theindicated field;.TP\-an optional digit string specifying a.I "field width;"if the converted value has fewer charactersthan the field widthit will be blank-padded on the left (or right,if the left-adjustment indicator has beengiven) 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 toseparate the field width from thenext digit string;.TP\-an optional digit stringspecifying a.I precisionwhich specifiesthe number of digits to appear after thedecimal point, for e- and f-conversion,or the maximum number of charactersto be printed from a string;.TP\-the character.B lspecifying that a following.BR d ,.BR o ,.BR x ,or.B ucorresponds to a long integer.I arg.(A capitalized conversion code accomplishesthe same thing.).TP\-a character which indicates the type ofconversion to be applied..PPA field width or precision may be `*' instead of a digit string.In this case an integer.I argsuppliesthe field width or precision..PPThe conversion charactersand their meanings are.TP.B doxThe integer.I argis converted to decimal, octal, orhexadecimal notation respectively..TP.B fThe float or double.I argis converted to decimal notationin the style `[\fB\-\fR]ddd.ddd'where the number of d's after the decimal pointis equal to the precision specificationfor the argument.If the precisionis missing,6 digits are given;if the precision is explicitly 0, no digits andno decimal point are printed..TP.B eThe float or double.I argis converted in the style`[\fB\-\fR]d\fB.\fRddd\fBe\fR\(+-dd'where there is one digit before the decimal point andthe number after is equal to theprecision specification for the argument;when the precision is missing,6 digits are produced..TP.B gThe float or double.I argis printed in style.BR d ,in style.BR f ,or instyle.BR e ,whichever gives full precision in minimum space..TP.B cThe character.I argis printed.Null characters are ignored..TP.B s.I Argis taken to be a string (character pointer)and characters from the string are printed untila null character or untilthe number of characters indicated by the precisionspecification is reached;however if the precision is 0 or missingall characters up to a null are printed..TP.B uThe unsigned integer.I argis converted to decimaland printed (the result will be in therange 0 to 65535)..TP.B %Print a `%'; no argument is converted..PPIn no case does a non-existent or small field widthcause truncation of a field;padding takes place only if the specified fieldwidth exceeds the actual width.Characters generated by.I printfare printed by .IR putc (3)..PP.B Examples.brTo print a date and time in the form `Sunday, July 3, 10:02',where.I weekdayand.I monthare pointers to null-terminated strings:.RS.HP.nhprintf("%s, %s %d, %02d:%02d", weekday, month, day, hour, min);.RE.hy.PPTo print.if n pi.if t \(*pto 5 decimals:.IPprintf("pi = %.5f", 4*atan(1.0));.SH "SEE ALSO"putc(3),scanf(3),ecvt(3).SH BUGSVery wide fields (>128 characters) fail.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -