我需要将一个double传递给我的程序,但以下内容不起作用:
int main(int argc, char *argv[]) {
double ddd;
ddd=atof(argv[1]);
printf("%f\n", ddd);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如果我运行我的程序,因为./myprog 3.14它仍然打印0.000000.
有人可以帮忙吗?
小智 8
我的猜测是你忘了包括在内#include <stdlib.h>.如果是这种情况,gcc将发出以下警告:
warning: implicit declaration of function 'atof' [-Wimplicit-function-declaration]
Run Code Online (Sandbox Code Playgroud)
并提供您提供的确切输出:0.000000.