-2

I'm working on a program that convert strings to integers. The code works just fine but I got this warning that I can't solve. I tried to look it up but nothing helpful was found.

Here is the simple code:

#include <stdio.h>

int main() {
    char x[8] = "ABCDWXYZ";
    long long sum = 0;

    for (int i = 0; i < 8; i++) {
        sum = sum * 100 + (long long)x[i];
    }
    printf("%lli", sum);

    return 0;
}

Here's the warning I got:

too many arguments for format [-Wformat-extra-args]  //Line 11
unknown conversion type character 'l' in format [-Wformat=]  //Line 11
Darth-CodeX
  • 2,166
  • 1
  • 6
  • 23
Alex
  • 1
  • 2

1 Answers1

1

Compiler, mingw v 6.2, with the compiler options used do not understand the "ll", in "%lli".

Alternatives.

  • Compile as C11. @Haris

  • Use a more up-to-date compiler. (OP implies this is not an option.)

  • Re-code and use some crafted helper function to output a 64-bit as decimal text.

  • Re-code and use compiler specific formats. Not reccomendeded.


OP's sum * 100 + (long long)x[i] is curious. To read 8 characters of an 8 character array and form all possible 64-bit values, I'd expect unsigned long long sum, sum * (UCHAR_MAX+1) + (unsigned char)x[i] and "%llu". That magic number 100 seems strange. Maybe OP meant 0x100?

chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256
  • 1
    I don't see why compiling as C11 would make any difference since the problem is non-conformance with C99. This whole thing is a known bug in Mingw + libs and the work-around is `#define __USE_MINGW_ANSI_STDIO 1` before including stdio.h. – Lundin Apr 12 '23 at 13:14