c - 在 C 中,LARGE_INTEGER.QuadPart 在 printf 中捕获两次

标签 c printf

我正在尝试打印文件的大小和名称。

LARGE_INTEGER filesize;
filesize.LowPart = ...
...
printf("%ld %s\n", filesize.QuadPart, file.cFileName);

这会导致

42 (null)

但是,当我额外添加一个 %s(以及第三个 %s)

printf("%ld %s %s %s\n", filesize.QuadPart, file.cFileName, "foo");

我明白了

42 (null) hello.c foo

显然,简单的解决方法就是在其自己的 printf 语句中隔离文件大小,但我仍然对为什么会发生这种情况感到困惑。

最佳答案

The correct way to print would be inttypes.h with the macro PRI64d. – Olaf

标准方法是使用宏PRId64,例如。克。

    printf("%"PRId64" %s\n", filesize.QuadPart, file.cFileName);

关于c - 在 C 中,LARGE_INTEGER.QuadPart 在 printf 中捕获两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34104972/

相关文章:

c - 这个 printf 技巧是如何工作的

c - 我在 c 中的 printf 函数没有打印任何内容

c - printf 无法在屏幕上正确打印 float/double

计算数组元素的百分比

c - 如何在 C 语言中更新 GTK+-3.0 中的标签

c - 如果使用了 malloc(),则函数在返回时崩溃

c - 使用 GNU make、嵌入式 C 进行 native 和交叉编译

c - 以十六进制格式打印 int(0x11 不是 0011)

c - 在 C 中编写我自己的管道函数

c - QueryPerformanceFrequency 与 CPU 速度不匹配?