gpt4 book ai didi

c - C 新手 : I need to read this line of data from file "-2.628489e-03 -1.194542e-03 -1.073491e-02 "

转载 作者:行者123 更新时间:2023-11-30 15:48:55 25 4
gpt4 key购买 nike

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

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

结果

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

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

最佳答案

使用正确的格式

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

参见code "running" at ideone with your inputs

关于c - C 新手 : I need to read this line of data from file "-2.628489e-03 -1.194542e-03 -1.073491e-02 ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16575605/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com