⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lib_prin.html

📁 ST20 Embedded Toolset R2.0.5用于开发基于ST20芯片机顶盒软件的开发平台,2.0.5版本,国内找不到的.在国外论坛上花了N天才找到!
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<HTML><HEAD><TITLE>Formatted Output</TITLE></HEAD><BODY><H1><A NAME="Formatted Output">Formatted Output</A></H1><HR><P><B><A HREF="#Print Formats">Print Formats</A>&#183; <A HREF="#Print Functions">Print Functions</A>&#183; <A HREF="#Print Conversion Specifiers">Print Conversion Specifiers</A></B></P><HR><P>Several library functions help you convert data values fromencoded internal representations to text sequences that aregenerally readable by people. You provide a<A HREF="#format string">format string</A> as the value of the<CODE>format</CODE> argument to each of these functions, hencethe term <B>formatted output</B>.The functions(declared in<A HREF="stdio.html#&lt;stdio.h&gt;"><CODE>&lt;stdio.h&gt;</CODE></A>)convert internal representations to sequences of type <I>char,</I>and help you compose such sequences for display:<A HREF="stdio.html#fprintf">fprintf</A>,<A HREF="stdio.html#printf">printf</A>,<A HREF="stdio.html#sprintf">sprintf</A>,<A HREF="stdio.html#vfprintf">vfprintf</A>,<A HREF="stdio.html#vprintf">vprintf</A>, and<A HREF="stdio.html#vsprintf">vsprintf</A>.For these function, a format string is a<A HREF="lib_over.html#multibyte string">multibyte string</A>that begins and ends in the<A HREF="charset.html#initial shift state">initial shift state</A>.</P><H2><A NAME="Print Formats">Print Formats</A></H2><P>A <B><A NAME="format string">format string</A></B> has the samesyntax for both the print functions and the<A HREF="lib_scan.html#Formatted Input">scan functions</A>,as shown in the diagram.</P><P><IMG SRC="format.gif"></P><P>A format string consists of zero or more<B><A NAME="conversion specification">conversion specifications</A></B>interspersed with literal text and<B><A NAME="white space">white space</A></B>.White space is a sequence of one or morecharacters <CODE>c</CODE> for which the call<CODE><A HREF="ctype.html#isspace">isspace</A>(c)</CODE> returns nonzero.(The characters defined as white space can change when you change the<A HREF="locale.html#LC_CTYPE"><CODE>LC_CTYPE</CODE></A><A HREF="locale.html#locale category">locale category</A>.)For the print functions, a conversion specification is one of the<A HREF="#print conversion specification">print conversion specifications</A> described below.</P><P>A print function scans the format string once from beginningto end to determine what conversions to perform. Every printfunction accepts a<A HREF="stdarg.html#varying number of arguments">varying numberof arguments</A>, either directly or under control of an argument of type<A HREF="stdarg.html#va_list"><CODE>va_list</CODE></A>.Some print conversion specificationsin the format string use the next argument in the list.A print function uses each successive argument no more thanonce. Trailing arguments can be left unused.</P><P>In the description that follows:</P><UL><LI><B><A NAME="integer conversions">integer conversions</A></B> are the<B><A NAME="conversion specifiers">conversion specifiers</A></B> thatend in <CODE>d</CODE>, <CODE>i</CODE>, <CODE>o</CODE>, <CODE>u</CODE>,<CODE>x</CODE>, or <CODE>X</CODE></LI><LI><B><A NAME="floating-point conversions">floating-point conversions</A></B>are the conversion specifiersthat end in <CODE>e</CODE>, <CODE>E</CODE>, <CODE>f</CODE>,<CODE>g</CODE>, or <CODE>G</CODE></LI></UL><H2><A NAME="Print Functions">Print Functions</A></H2><P>For the print functions, literal text or<A HREF="#white space">white space</A> in a formatstring generates characters that match the characters in the formatstring. A<B><A NAME="print conversion specification">print conversion specification</A></B> typically generates charactersby converting the next argument value to a corresponding text sequence.A print conversion specification has the format:</P><P><IMG SRC="print.gif"></P><P><B>Boldface</B> indicates a feature added with<A HREF="lib_over.html#C99">C99</A>.</P><P>Following the percent character (<B><CODE>%</CODE></B>)in the format string, you can write zero or more<B><A NAME="format flag">format flags</A></B>:</P><UL><LI><B><CODE>-</CODE></B>-- to left-justify a conversion</LI><LI><B><CODE>+</CODE></B>-- to generate a plus sign for signed values thatare positive</LI><LI><B><CODE><I>space</I></CODE></B>-- to generate a <CODE><I>space</I></CODE> for signed valuesthat have neither a plus nor a minus sign</LI><LI><B><CODE>#</CODE></B>-- to prefix <CODE>0</CODE> on an <CODE>o</CODE> conversion,to prefix <CODE>0x</CODE> on an <CODE>x</CODE> conversion,to prefix <CODE>0X</CODE> on an <CODE>X</CODE> conversion,or to generate a decimal point and fractiondigits that are otherwise suppressed on a floating-point conversion</LI><LI><B><CODE>0</CODE></B>-- to pad a conversion with leading zeros afterany sign or prefix, in the absence of a minus (<CODE>-</CODE>)format flag or a specified precision</LI></UL><P>Following any format flags, you can write a<B><A NAME="print field width">field width</A></B> thatspecifies the minimum number of characters to generate for the conversion.Unless altered by a format flag,the default behavior is to pad a short conversionon the left with <CODE><I>space</I></CODE> characters.If you write an asterisk (<B><CODE>*</CODE></B>)instead of a decimal number for a field width, then a printfunction takes the value of the next argument (which must be of type<I>int</I>) as the field width. If the argument value is negative,it supplies a <CODE>-</CODE> format flagand its magnitude is the field width.</P><P>Following any field width, you can write a dot (<B><CODE>.</CODE></B>)followed by a<B><A NAME="precision">precision</A></B>that specifies one of the following:the minimum number of digits to generate on an integer conversion;the number of fraction digits to generate on an <CODE>e</CODE>,<CODE>E</CODE>, or <CODE>f</CODE> conversion;the maximum number of significant digits to generateon a <CODE>g</CODE> or <CODE>G</CODE> conversion; or the maximum numberof characters to generate from a<A HREF="lib_over.html#C string">C string</A>on an <CODE>s</CODE> conversion.</P><P>If you write an <B><CODE>*</CODE></B> instead ofa decimal number for a precision,a print function takes the value of the next argument (which mustbe of type <I>int</I>) as the precision. If the argument value isnegative, the default precision applies. If you do not write eitheran <CODE>*</CODE> or a decimal number following the dot, the precisionis zero.</P><H2><A NAME="Print Conversion Specifiers">Print Conversion Specifiers</A></H2><P>Following any<A HREF="#precision">precision</A>,you must write a one-character <B>print conversion specifier</B>,possibly preceded by a one- or two-character qualifier.Each combination determines the type required of thenext argument (if any) and how the library functions alter the argumentvalue before converting it to a text sequence.The <A HREF="#integer conversions">integer</A> and<A HREF="#floating-point conversions">floating-point conversions</A> also determinewhat base to use for the text representation.If a conversion specifier requires a precision <I>p</I> and you donot provide one in the format, then the conversion specifier choosesa default value for the precision. The following tablelists all defined combinations and their properties.</P><PRE><B>Conversion</B>  <B>Argument</B>        <B>Converted</B>          <B>Default  Pre-</B> <B>Specifier</B>    <B>Type</B>            <B>Value</B>              <B>Base</B>  <B>cision</B>   %c       int x          (unsigned char)x   %d       int x          (int)x                 10     1

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -