使用printf时, 记住使用哪个字符格式化输出很麻烦, 常用的int/long还好记, 遇到int_32/size_t这种就麻爪了. 每次都要网上查下,

C99标准的§7.19.6.1 (7)有定义, 但是每次翻pdf好麻烦, 而且显示的也不是那么易懂. 这里推荐cppreference, 使用图表格式, 十分易懂.

Conversion
specifier
Explanation Argument type
length modifier hh

(C99)

h (none) l ll

(C99)

j

(C99)

z

(C99)

t

(C99)

L
% writes literal %. The full conversion specification must be %%. N/A N/A N/A N/A N/A N/A N/A N/A N/A
c

writes a single character.

The argument is first converted to unsigned char. If the l modifier is used, the argument is first converted to a character string as if by %ls with a wchar_t[2]argument.

N/A N/A

int

wint_t

N/A N/A N/A N/A N/A
s

writes a character string

The argument must be a pointer to the initial element of an array of characters. Precision specifies the maximum number of bytes to be written. If Precision is not specified, writes every byte up to and not including the first null terminator. If the l specifier is used, the argument must be a pointer to the initial element of an array of wchar_t, which is converted to char array as if by a call to wcrtomb with zero-initialized conversion state.

N/A N/A

char*

wchar_t*

N/A N/A N/A N/A N/A
d
i

converts a signed integer into decimal representation [-]dddd.

Precision specifies the minimum number of digits to appear. The default precision is 1.
If both the converted value and the precision are ​0​ the conversion results in no characters.

signed char

short

int

long

long long

intmax_t

signed size_t

ptrdiff_t

N/A
o

converts a unsigned integer into octal representation oooo.

Precision specifies the minimum number of digits to appear. The default precision is 1. If both the converted value and the precision are ​0​ the conversion results in no characters. In the alternative implementationprecision is increased if necessary, to write one leading zero. In that case if both the converted value and the precision are ​0​, single ​0​ is written.

unsigned char

unsigned short

unsigned int

unsigned long

unsigned long long

uintmax_t

size_t

unsigned version of ptrdiff_t

N/A
x
X

converts an unsigned integer into hexadecimal representation hhhh.

For the x conversion letters abcdef are used.
For the X conversion letters ABCDEF are used.
Precision specifies the minimum number of digits to appear. The default precision is 1. If both the converted value and the precision are ​0​ the conversion results in no characters. In the alternative implementation 0x or 0Xis prefixed to results if the converted value is nonzero.

N/A
u

converts an unsigned integer into decimal representation dddd.

Precision specifies the minimum number of digits to appear. The default precision is 1. If both the converted value and the precision are ​0​ the conversion results in no characters.

N/A
f
F

converts floating-point number to the decimal notation in the style [-]ddd.ddd.

Precision specifies the minimum number of digits to appear after the decimal point character. The default precision is 6. In the alternative implementationdecimal point character is written even if no digits follow it. For infinity and not-a-number conversion style see notes.

N/A N/A

double

double (C99)

N/A N/A N/A N/A

long double

e
E

converts floating-point number to the decimal exponent notation.

For the e conversion style [-]d.ddde±dd is used.
For the E conversion style [-]d.dddE±dd is used.
The exponent contains at least two digits, more digits are used only if necessary. If the value is ​0​, the exponent is also ​0​. Precision specifies the minimum number of digits to appear after the decimal point character. The default precision is 6. In the alternative implementationdecimal point character is written even if no digits follow it. For infinity and not-a-number conversion style see notes.

N/A N/A N/A N/A N/A N/A
a
A

(C99)

converts floating-point number to the hexadecimal exponent notation.

For the a conversion style [-]0xh.hhhp±d is used.
For the A conversion style [-]0Xh.hhhP±d is used.
The first hexadecimal digit is not 0 if the argument is a normalized floating point value. If the value is ​0​, the exponent is also ​0​. Precision specifies the minimum number of digits to appear after the decimal point character. The default precision is sufficient for exact representation of the value. In the alternative implementation decimal point character is written even if no digits follow it. For infinity and not-a-number conversion style see notes.

N/A N/A N/A N/A N/A N/A
g
G

converts floating-point number to decimal or decimal exponent notation depending on the value and the precision.

For the g conversion style conversion with style e or f will be performed.
For the G conversion style conversion with style E or F will be performed.
Let P equal the precision if nonzero, 6 if the precision is not specified, or 1 if the precision is ​0​. Then, if a conversion with style E would have an exponent of X:

  • if P > X ≥ −4, the conversion is with style f or F and precision P − 1 − X.
  • otherwise, the conversion is with style e or E and precision P − 1.

Unless alternative representation is requested the trailing zeros are removed, also the decimal point character is removed if no fractional part is left. For infinity and not-a-number conversion style see notes.

N/A N/A N/A N/A N/A N/A
n

returns the number of characters written so far by this call to the function.

The result is written to the value pointed to by the argument. The specification may not contain any flagfield width, or precision.

signed char*

short*

int*

long*

long long*

intmax_t*

signed size_t*

ptrdiff_t*

N/A
p writes an implementation defined character sequence defining a pointer. N/A N/A void* N/A N/A N/A N/A N/A N/A

https://en.cppreference.com/w/c/io/fprintf

这里提供两个C99标准文件地址供大家参考(正式官方标准不在官网提供, 需要购买. 你可以在"http://www.open-std.org/jtc1/sc22/wg14/ "找到准正式版本):

http://www.dii.uchile.cl/~daespino/files/Iso_C_1999_definition.pdf

http://www.open-std.org/jtc1/sc22/wg14/www/C99RationaleV5.10.pdf

C99/Cpp 使用printf 时format大全相关推荐

  1. java输出数字与字符串_数字与字符串系列教材 (四)- Java 使用printf或format 进行格式化输出...

    步骤1:格式化输出 步骤2:printf和format 步骤3:换行符 步骤4:总长度,左对齐,补0,千位分隔符,小数点位数,本地化表达 步骤5:练习-黄鹤 步骤6:答案-黄鹤 步骤 1 : 格式化输 ...

  2. printf 中转义字符大全

    表一转换说明符及作为结果的打印输出 转换说明 输出 %a 浮点数.十六进制数字和p-记数法 (C99) %A 浮点数.十六进制数字和P-记数法 (C99) %c 一个字符 %d 有符号十进制整数 %e ...

  3. JavaScript等同于printf / String.Format

    我正在寻找一个等效于C / PHP printf()或C#/ Java程序员的String.Format() (适用于.NET的IFormatProvider String.Format() Java ...

  4. ccs用C语言进行printf时,PIC单片机CCS之C语言(#FUSES的用法)

    #FUSES 语法: #fuse options options要根据设备改变.一系列有效的可选项都要放在每个devices.h文件的顶部,注释用来参考.PCW能有效编辑修改特殊的设备fuses.PC ...

  5. ccs用C语言进行printf时,DSP:CCS V6 TMS320F2812 使用printf函数

    使用Code Composer Studio  Version: 6.1.1.00022,建立TMS320F2812工程. /* * main.c */ #include int main(void) ...

  6. VC 工程中包含 .c 或cpp文件编译时产生的.pch预编译头错误(C1853)

    编写混合  时出现这样错误"fatal error C1853: "Debug\SMS_Test.pch"预编译头文件来自编译器的早期版本,或者预编译头为 C++ 而在 ...

  7. string.format大全

    字符串的数字格式 stringstr1 =string.Format("{0:N1}",56789);               //result: 56,789.0 strin ...

  8. c语言format是什么,初始化C盘时format c:/s 中/s是什么意思啊?

    FORMAT volume [/FS:file-system] [/V:label] [/Q] [/A:size] [/C] [/X] FORMAT volume [/V:label] [/Q] [/ ...

  9. stm32学习笔记----双串口同时打开时的printf()问题

    stm32学习笔记----双串口同时打开时的printf()问题 最近因为要使用串口2外接PN532芯片实现通信,另一方面,要使用串口1来将一些提示信息输出到上位机,于是重定义了printf(),使其 ...

最新文章

  1. 编写你的第一个 Flutter App
  2. Tensorflow学习: 乘法demo
  3. opencv精要(4)-fedora下的opencv安装及测试,codelite配置
  4. linux 进程可以把自己,如何将Linux进程小隐于用户?仅仅一行代码即可
  5. 带Lambda表达式的Apache Wicket
  6. 周五跟大佬喝酒,顺便打了个球
  7. dabeicun 2013源码下载
  8. [转载] 大型网站的 HTTPS 实践(一)—— HTTPS 协议和原理
  9. pandas 计算工具
  10. 漫谈广告竞价模式(一)
  11. 买茶叶想到的哪个比较便宜 x1/y1 x2/y2 x代表多少钱 y代表 多少克 无聊的试炼...
  12. tornado celery mysql_tornado中使用celery实现异步MySQL操作
  13. 区块链 共识算法 分类
  14. hdoj1003+codeup2086:Max Sum最大连续子序列和(dp基础题+dp入门-----分治/遍历求和/dp)
  15. oracle 12c 自增序列
  16. 1.19.10.Flink SQL工程案例\Flink批式处理\自定义函数\Window窗口计算\将DataSet数据转成Table数据\将Table数据转成DataSet等
  17. 如何看待用户反馈意见
  18. 【腾讯位置服务】使用地点云实现企业官网中的门店地图
  19. Holy Grail 2019南京网络赛
  20. 汇编 输入成绩,排序输出,平均值,及格,不及格人数,最大最小值

热门文章

  1. 黑鹰ASP.NET教程
  2. 安装mavros时,运行 wstool update -t src -j8 时出错解决
  3. 修改google搜索引擎非hk方法
  4. IDL编译器系列-入门篇
  5. LDAP(Lightweight Directory Access Protocol)介绍
  6. 数字视音频处理知识点小结
  7. ping命令简单总结
  8. HackTheBox——Beep
  9. 简单python脚本实例画图-Python使用matplotlib简单绘图示例
  10. python e指数函数,常用的e指数代码