格式说明符%Lf为`long double`变量给出错误 [英] Format specifier %Lf is giving errors for `long double` variables

查看:171
本文介绍了格式说明符%Lf为`long double`变量给出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到以下错误:

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

据我所知,long double的格式说明符为%Lf,因此不确定如何解决该问题.谢谢!

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!

DEV-C ++ 中与TDM-GCC 4.9.2 64-bit Release一起编译.

推荐答案

您的编译器无法识别%Lf,您需要提供编译器标志-D__USE_MINGW_ANSI_STDIO=1

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

示例:

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

在使用Dev-C++时,您可能还应该添加-std=c11标志以启用C11标准.

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

此线程说明了应如何将标志添加到Dev-C++:

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

如何将模式从Dev-C ++中的c ++ 98模式更改为支持C ++ 0x的模式(基于)?

因此,您需要使用链接线程中的指令添加标志-std=c11-D__USE_MINGW_ANSI_STDIO=1.

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

由于Dev-C ++使用的是较旧的标准,因此仅添加-std=c11即可解决此问题.先尝试一下.

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

这篇关于格式说明符%Lf为`long double`变量给出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆