- 论坛徽章:
- 1
|
man 3 printf
字符串 %2$s 中有 %1$d 个字符就可以了。
- To print a date and time in the form `Sunday, July 3, 10:02', where weekday and month are pointers to strings:
- #include <stdio.h>
- fprintf(stdout, "%s, %s %d, %.2d:%.2d\n",
- weekday, month, day, hour, min);
- Many countries use the day-month-year order. Hence, an internationalized version must be able to print the arguments in an order specified by the
- format:
- #include <stdio.h>
- fprintf(stdout, format,
- weekday, month, day, hour, min);
- where format depends on locale, and may permute the arguments. With the value:
- "%1$s, %3$d. %2$s, %4$d:%5$.2d\n"
- one might obtain `Sonntag, 3. Juli, 10:02'.
复制代码
[ 本帖最后由 flw 于 2008-6-24 16:42 编辑 ] |
|