什么是错的ATOF功能的使用情况如何? [英] What is wrong with usage of atof function?

查看:217
本文介绍了什么是错的ATOF功能的使用情况如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  INT的main()
{
    炭海峡[10] =3.5;
    的printf(%LF,ATOF(STR));
    返回0;
}

这是一个简单的code,我在ideone.com测试。我得到的输出

  -0.371627


解决方案

您还没有包括stdlib.h中。添加适当的包括:

 的#include<&stdio.h中GT;
#包括LT&;&stdlib.h中GT;诠释的main()
{
    炭海峡[10] =3.5;
    的printf(%LF,ATOF(STR));
    返回0;
}

不包括stdlib.h中, ATOF()是隐含声明,编译器假定它返回一个int。

int main()
{
    char str[10]="3.5";
    printf("%lf",atof(str));
    return 0;
}

This is a simple code I am testing at ideone.com. I am getting the output as

-0.371627

解决方案

You have not included stdlib.h. Add proper includes:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char str[10]="3.5";
    printf("%lf",atof(str));
    return 0;
}

Without including stdlib.h, atof() is declare implicitly and the compiler assumes it returns an int.

这篇关于什么是错的ATOF功能的使用情况如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆