gpt4 book ai didi

C: 将 argv[1] 转换为 double

转载 作者:太空狗 更新时间:2023-10-29 16:52:58 32 4
gpt4 key购买 nike

我需要向我的程序传递一个 double,但以下方法不起作用:

int main(int argc, char *argv[]) {

double ddd;

ddd=atof(argv[1]);

printf("%f\n", ddd);

return 0;
}

如果我以 ./myprog 3.14 运行程序,它仍会打印 0.000000

有人可以帮忙吗?

最佳答案

我猜你忘了包含 #include <stdlib.h> .如果是这种情况,gcc将发出以下警告:

warning: implicit declaration of function 'atof' [-Wimplicit-function-declaration]

并给出您提供的确切输出:0.000000 .

关于C: 将 argv[1] 转换为 double,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20578187/

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