解决方案 »

  1.   

    而你那个是.s的格式,就是输出指定个数的字符,比如一个字符串是abcdef,输出用.2s,输出的内容就是ab
      

  2.   

    %s 如果加%.ns 表示格式化输出n个字符
      

  3.   

    Precision Specification
    The third optional field of the format specification is the precision specification. It specifies a nonnegative decimal integer, preceded by a period (.), which specifies the number of characters to be printed, the number of decimal places, or the number of significant digits (see Table R.5). Unlike the width specification, the precision specification can cause either truncation of the output value or rounding of a floating-point value. If precision is specified as 0 and the value to be converted is 0, the result is no characters output, as shown below:printf( "%.0d", 0 );      /* No characters output */If the precision specification is an asterisk (*), an int argument from the argument list supplies the value. The precision argument must precede the value being formatted in the argument list.The type determines the interpretation of precision and the default when precision is omitteds, S The precision specifies the maximum number of characters to be printed. Characters in excess of precision are not printed. Characters are printed until a null character is encountered