好久不用C了,这次用到atof()函数,字符串转成浮点数,但老是不成功,转成的值非常奇怪
- #include <stdio.h>
- void main()
- {
- char str[6] = " 97.2";
- printf("%lf\n", atof(str));
- }
编译的时候出现warning:a.c: In function ‘main’:
a.c:6: warning: format ‘%lf’ expects type ‘double’, but argument 2 has type ‘int’
这个结果不算什么,我用在另一个地方转成的值更离谱。
再次查了一下atof()的manpage,终于发现头文件居然是
.
#include <stdio.h>
#include
- void main()
- {
- char str[6] = " 97.2";
- printf("%lf\n", atof(str));
- }
这样才是对的.
可见有一个默认的atof()存在于Linux系统中。
阅读(5023) | 评论(0) | 转发(0) |