0

我已经尝试过 %f %g %e 和相同的长版本。

例如。fscanf(inFile,"%g %g %g ",&c0,&c1,&c2);

结果是

-1.1546e+09 -1.16415e+09 -1.13768e+09

有人可以告诉我使用什么格式吗?谢谢!

4

2 回答 2

1

使用正确的格式

#include <stdio.h>

int main(void) {
    float f1, f2, f3;
    double d1, d2, d3;
    long double l1, l2, l3;

    fscanf(stdin, "%f%f%f", &f1, &f2, &f3);    /* scan floats */
    fscanf(stdin, "%lf%lf%lf", &d1, &d2, &d3); /* scan doubles */
    fscanf(stdin, "%Lf%Lf%Lf", &l1, &l2, &l3); /* scan long doubles */

    printf("floats: %f %f %f\n", f1, f2, f3);   /* print floats (they're automagically converted to doubles) */
    printf("doubles: %f %f %f\n", d1, d2, d3);  /* print doubles */
    printf("longs: %Lf %Lf %Lf\n", l1, l2, l3); /* print long doubles */

    return 0;
}

使用您的输入查看ideone 上“运行”的代码

于 2013-05-15T21:59:37.230 回答
0

c的情况?是双

double c0,c1,c2;
fsscanf(inFile, "%lf %lf %lf", &c0,&c1,&c2);

c的情况?是浮动的

float c0,c1,c2;
fsscanf(inFile, "%f %f %f", &c0,&c1,&c2);
于 2013-05-15T21:58:50.753 回答