user-0 提问: C语言字段宽度这块儿的疑问，请大伽指点一下迷津

回复:
user: user-1
content: Format Specification Fields: printf and wprintf Functions A format specification, which consists of optional and required fields, has the following form:  %[flags] [width] [.precision] [{h | l | I64 | L}]type  Each field of the format specification is a single character or a number signifying a particular format option. The simplest format specification contains only the percent sign and a type character (for example, %s). If a percent sign is followed by a character that has no meaning as a format field, the character is copied to stdout. For example, to print a percent-sign character, use %%.  The optional fields, which appear before the type character, control other aspects of the formatting, as follows:  type  Required character that determines whether the associated argument is interpreted as a character, a string, or a number (see Table R.3).  flags  Optional character or characters that control justification of output and printing of signs, blanks, decimal points, and octal and hexadecimal prefixes (see Table R.4). More than one flag can appear in a format specification.  width  Optional number that specifies the minimum number of characters output. (See printf Width Specification.)   precision  Optional number that specifies the maximum number of characters printed for all or part of the output field, or the minimum number of digits printed for integer values (see Table R.5).  h | l | I64 | L  Optional prefixes to type-that specify the size of argument (see Table R.6).    Flag Directives The first optional field of the format specification is flags. A flag directive is a character that justifies output and prints signs, blanks, decimal points, and octal and hexadecimal prefixes. More than one flag directive may appear in a format specification.   Table R.4   Flag Characters  Flag Meaning Default  – Left align the result within the given field width.  Right align.  + Prefix the output value with a sign (+ or –) if the output value is of a signed type. Sign appears only for negative signed values (–).  0 If width is prefixed with 0, zeros are added until the minimum width is reached. If 0 and – appear, the 0 is ignored. If 0 is specified with an integer format (i, u, x, X, o, d) the 0 is ignored.  No padding.  blank (' ') Prefix the output value with a blank if the output value is signed and positive; the blank is ignored if both the blank and + flags appear. No blank appears.  # When used with the o, x, or X format, the # flag prefixes any nonzero output value with 0, 0x, or 0X, respectively. No blank appears.    When used with the e, E, or f format, the # flag forces the output value to contain a decimal point in all cases.  Decimal point appears only if digits follow it.    When used with the g or G format, the # flag forces the output value to contain a decimal point in all cases and prevents the truncation of trailing zeros.  Ignored when used with c, d, i, u, or s.  Decimal point appears only if digits follow it. Trailing zeros are truncated.    printf Width Specification The second optional field of the format specification is the width specification. The width argument is a nonnegative decimal integer controlling the minimum number of characters printed. If the number of characters in the output value is less than the specified width, blanks are added to the left or the right of the values — depending on whether the – flag (for left alignment) is specified — until the minimum width is reached. If width is prefixed with 0, zeros are added until the minimum width is reached (not useful for left-aligned numbers).  The width specification never causes a value to be truncated. If the number of characters in the output value is greater than the specified width, or if width is not given, all characters of the value are printed (subject to the precision specification).  If the width specification is an asterisk (*), an int argument from the argument list supplies the value. The width argument must precede the value being formatted in the argument list. A nonexistent or small field width does not cause the truncation of a field; if the result of a conversion is wider than the field width, the field expands to contain the conversion result.  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.

user: user-2
content: printf("%20s"...)默认是右对齐，如果让左对齐的话printf("%-20s");

user: user-3
content: 首先你要保证你的输入是有效的，你已经越界赋值了，谁能保证程序运行的结果预期？  printf("\"%8s%-s\"\n",name,name1); 网上搜索下printf格式的说明，这里的8代表宽度，如果字符串长度>8，那么字符串将会完整显示（不会截断的） - 代表左对齐

user: user-0
content: 是没有搞懂这个具体应该怎么用

user: user-4
content: 字符串越界了吧？