Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c

c99

scanf

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

like image 260
Tomáš Zato - Reinstate Monica Avatar asked May 18 '14 02:05

Tomáš Zato - Reinstate Monica


2 Answers

Just wanted to add this snippet too:

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.

like image 114
sdbbs Avatar answered Nov 08 '22 19:11

sdbbs


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.

like image 30
Jens Gustedt Avatar answered Nov 08 '22 19:11

Jens Gustedt