我正在尝试打印文件的大小和名称。
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 macroPRI64d
. – Olaf
标准方法是使用宏PRId64
,例如。克。
printf("%"PRId64" %s\n", filesize.QuadPart, file.cFileName);
关于c - 在 C 中,LARGE_INTEGER.QuadPart 在 printf 中捕获两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34104972/