我对Atof函数有问题。我正在尝试将字符串转换为浮点数,但当我在调试部分尝试使用Coocox软件时,它没有给出任何错误,输出没有显示任何内容。我尝试了两个函数Atoi和Atof。当我使用Atoi的时候,没有output.When,我使用的是启动重启的程序.我将atof的stdlib.h定义放在here.But中,这里的浮点值是atoff。我用C语言在Dev C++中尝试了同样的代码,它工作得很好。我在没有工作的情况下使用的其他东西,但这一次程序再次重新启动。这在Dev C上有效,但在Coocox上不起作用。我该如何解决这个问题?唯一的区别就是关了!这又有什么关系呢?我使用的是stdlib.h,编译过程中没有错误!
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main ()
{
float c;
int b;
char *array[1] = {"52.43525"};
b=(atoi(array[0])/100);
c=((atof(array[0]))/100.0)*100.0;
c/=60;
c+=b;
printf ("%f\n", c);
return 0;
}
-----stdlib.h----
double _EXFUN(atof,(const char *__nptr));
#if __MISC_VISIBLE
float _EXFUN(atoff,(const char *__nptr));
#endif
int _EXFUN(atoi,(const char *__nptr));
int _EXFUN(_atoi_r,(struct _reent *, const char *__nptr));
long _EXFUN(atol,(const char *__nptr));
long _EXFUN(_atol_r,(struct _reent *, const char *__nptr));
------------------------------------发布于 2017-09-18 00:05:55
更正所有编译器警告后,结果代码如下:
注意:由于没有使用数组特性,我将其更改为一个简单的指针。这对输出没有影响。
#include <stdio.h> // printf()
//#include <string.h> -- contents not used
#include <stdlib.h> // atoi(), atof()
int main ()
{
float c;
int b;
char *array = {"52.43525"};
b = atoi(array);
c = ( (float)( atof(array) ) / 100.0f ) * 100.0f;
c /= 60.0f;
c += (float)b;
printf ("%f\n", c);
return 0;
}运行该程序会导致:
52.873920因此,如果您的编译器找不到atof(),这就是编译器的问题。
https://stackoverflow.com/questions/46264945
复制相似问题