c - 错误 : unknown conversion type character 'l' in format - scanning long long

标签 c scanf c99

我正在尝试使用标准 IO 函数 scanf 从控制台获取 long long。我从 %lld 开始:

scanf("%lld", &rule);

抛出:

error: unknown conversion type character 'l' in format [-Werror=format=]

我找到了 more workarounds ,但它们也会抛出错误:

 scanf("%I64d", &rule);
   ->error: ISO C does not support the 'I64' ms_scanf length modifier [-Werror=format=]
 scanf("%"SCNd64"", &rule);
   ->error: expected ')' before 'SCNd64'

我做错了什么吗?还有其他技巧吗?

我正在使用这些标志在最新版本的 MinGw GCC 上进行编译:-pedantic -Wall -Werror -std=c99 -g -D HOME=1

最佳答案

我也想添加这个片段:

MinGW-w64 - for 32 and 64 bit Windows / [Mingw-w64-public] -Wformat and %llu

the issue is that formatter-width specifier %ll isn't supported for all msvcrt-DLL versions, therefore gcc warns about its use. The variant for specifying 64-bit integer-scalar-width in formatter for msvcrt in a backward-compatible way is by using %I64.

Use %I64u on Windows, or just use inttypes.h PRIuMAX.

If you must use %llu, define __USE_MINGW_ANSI_STDIO macro before including stdio.h. Be aware that if you do this, MS type %I64* format will no longer work.

关于c - 错误 : unknown conversion type character 'l' in format - scanning long long,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23718110/

相关文章:

c - 使用指向单个值的指针作为数组

c - dup 系统调用说明

c++ - 操作系统编程

c++ - Powershell 使用 scanf 进行编程的管道

C - 在输入流中分隔字符串

c - 灵活的数组成员,不必是最后一个

c - 优化以下 hackerrank 程序

c - 指向局部指针数组的全局指针

c - 如果输入是一个字母,它将无限次输出默认值

c - "int"真的需要至少与 C 中的 "short"一样大吗?