2

I am getting the following errors:

In function 'main':
[Warning] unknown conversion type character 'L' in format [-Wformat=]
[Warning] too many arguments for format [-Wformat-extra-args]

In function 'error_user':
[Warning] unknown conversion type character 'L' in format [-Wformat=]
[Warning] too many arguments for format [-Wformat-extra-args]

In the below code:

#include <stdio.h>
#include <stdlib.h>

void error_user (long double *error);

int main(void)
{
    long double error;

    printf("What error do you want?\n");

    error_user (&error);

    printf("%Lf\n", error);

    return 0;
}

void error_user (long double *error)
{
    scanf("%Lf", error);
}

As far as I know the format specifier of a long double is %Lf so not really sure how to solve this one. Thank you!

Compiled with TDM-GCC 4.9.2 64-bit Release in DEV-C++.

anastaciu
  • 23,467
  • 7
  • 28
  • 53
Henry
  • 697
  • 1
  • 6
  • 16

1 Answers1

1

Your compiler doesn't recognize %Lf , you need to provide the compiler flag -D__USE_MINGW_ANSI_STDIO=1

Example:

$ gcc filename.c -Wall -Wextra -pedantic -O3 -D__USE_MINGW_ANSI_STDIO=1
                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^

As you are using Dev-C++, you should probably also add -std=c11 flag to enable C11 standard.

This thread explains how you should add flags to Dev-C++:

How to change mode from c++98 mode in Dev-C++ to a mode that supports C++0x (range based for)?

So you need to add the flags -std=c11 and -D__USE_MINGW_ANSI_STDIO=1 using the instructions in the linked thread.

Since Dev-C++ uses an older standard, it's possible that adding only -std=c11 can solve the issue. Try it first.

anastaciu
  • 23,467
  • 7
  • 28
  • 53
  • hey @anastaciu Also, even though the warning doesn't appear any more (now I have also added `-std=c11`) , I am still wondering whether the variable is actually treated as a `long double`. Reason I ask because when I enter a value with more than 6 decimals i.e. `0.00000000001` I am still getting a 6 decimal output: `0.000000` – Henry Jun 13 '20 at 13:39
  • @Henry, the default number of declmal places is 6, you'll need to increase that, `%.12Lf`. – anastaciu Jun 13 '20 at 13:41
  • Right, so format specifier allows you to tell the compiler to allocate `X` amount of memory, and that doesn't necessarily affect the number of decimals that are being stored. For that you actually need to further specify it with the prefix `.12` resulting in `%.12Lf`. Would that be correct @anastaciu? – Henry Jun 13 '20 at 13:43
  • @Henry. the prefix should only be used in `printf` not in `scanf`, the amount of memory is defined by the type, the prefix `.12` is just to signal that you need to print 12 decimal places instead of the default 6. – anastaciu Jun 13 '20 at 13:48
  • 1
    All clear, thank you very much @anastaciu for all your great help!!! :-) – Henry Jun 13 '20 at 13:51