gpt4 book ai didi

c - atof 读取字符串为 0

转载 作者:行者123 更新时间:2023-12-02 08:35:24 26 4
gpt4 key购买 nike

我想我只是太笨了(我都试过了)。帮我离开这里:

#include <stdio.h>
#include <string.h>
int main()
{
const char * y = "747.0";
double x;
x = atof(y);
printf("%.5f\n",x);
printf("%e\n",x);
return 0;
}

结果:

0.00000
0.000000e+00

最佳答案

你需要包含 stdlib.h 来提供 atof() 一个原型(prototype),如果没有合适的原型(prototype),编译器会认为它的返回值是一个 int.

关于c - atof 读取字符串为 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22120743/

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