1. Call format printf ("< formatted string >", < parameter table >);
where the formatted string consists of two parts:: part of the normal character, these characters will be based on the originalSample Output; the other part is the formatting of the specified character, in"%"Start, followed by one or several specified characters, used to determine the output content format. Parameter table is a series of parameters that need to be output,The number must match the output indicated by the formatted string as many as the number of arguments, between the parameters with","separate, and order one by one corresponds, Otherwise there will be intentnot to the error.
2. Formatting characters
%ddecimal signed integer
%udecimal unsigned integer
%ffloating point number
%sstring
%cSingle character
%pthe value of the pointer
%efloating-point numbers in exponential form
%x,%xunsigned integer in hexadecimal notation
%0unsigned integer represented in octal
%gautomatic selection of appropriate representations
Description:
(1).can be in"%"Insert a number between the letters to indicate the maximum field width. For example:%3drepresents the output3number of bit integers, Not enough3right-aligned. %9.2findicates the output field width is9the floating-point number, where the decimal digit is2,the integer digits are6,The decimal point occupies one digit, Not enough 9right-aligned. %8srepresents the output8characters of a string, Not enough8The word aligns is aligned. if the length of the string, or the number of integers exceeds the description of the field width, will be output at its actual length. but for floating-point numbers, if the integer number of bits exceeds the width of the indicated integer digits, will be output as actual integer digits; if the fractional number of digits exceeds the width of the indicated decimal place, The output is rounded by the width of the description. Otheroutside, If you want to add a bit before the output value0,you should add one before the field width0. For example:%04drepresents the output of a less than4bit value when, will be in front of the fill0make its total widthto be4bit. if the output format of a character or integer is represented by a floating-point number, the number after the decimal point represents the maximum width, the number before the decimal point represents the minimum width. For example:%6.9sindicates that a length is not less than6and not greater than9the string. If greater than9,theSection9characters will be deleted later.
(2).can be in"%"and letters with lowercase lettersL,indicates that the output is a long type. For example:%ldrepresents the outputLonginteger,%lfrepresents the outputDoublefloating-point number.
(3).you can control the output left-justified or right-justified, that is in"%"and letters to add a"-" Number candescription Output is left justified, Otherwise, right-aligned. For example:%-7drepresents the output7bit integers left-aligned,%-10srepresents the outputTenThe word aligns is aligned.
3. Some special provisions of the character
\ nline Break
\fClear screen and change page
\ rEnter
\ t Tabcharacter
\xhhrepresents aASCIICode with -Input Representation,
whichhhis a1to the2a -binary number
C-language printf