2

我收到以下错误:

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]

在下面的代码中:

#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);
}

据我所知,a 的格式说明符long double不太%Lf确定如何解决这个问题。谢谢!

TDM-GCC 4.9.2 64-bit ReleaseDEV-C++中编译。

4

1 回答 1

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.

于 2020-06-13T12:50:34.387 回答