error: unknown conversion type character 'l' in format - scanning long long

Tomáš Zato - Reinstate Monica picture Tomáš Zato - Reinstate Monica · May 18, 2014 · Viewed 9.4k times · Source

I'm trying to get long long from the console using standard IO function scanf. I started with %lld:

scanf("%lld", &rule);

That throws:

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

I've found more workarounds, but they too throw errors:

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

Am I doing something wrong? Is there an another trick?

I'm compiling on very recent version of MinGw GCC with these flags: -pedantic -Wall -Werror -std=c99 -g -D HOME=1

Answer

Jens Gustedt picture Jens Gustedt · May 18, 2014

for SCNd64 and similar, you'd have to use

#include <inttypes.h>

but all of this is only supposed to work if your compiler supports C99. Your first error message is a strong indication that it doesn't, or that you didn't give the right commandline switches.