为什么strtof总是在评估HUGE_VAL?

use*_*747 4 c

这可能是什么问题?无论我选择什么数字为str,它始终是2681561585988519419914804999641169225495873164118478675544712​​2887443528060147093953603748596333806855380063716372972101707507765623893139892867298012168192.00

char *str = "2.6";
printf("%f\n", strtof(str, (char**)NULL));
//prints 26815615859885194199148049996411692254958731641184786755447122887443528060147093953603748596333806855380063716372972101707507765623893139892867298012168192.00
Run Code Online (Sandbox Code Playgroud)

整个计划:

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

int main(int argc, char *argv[])
{
    char *str = "2.6";
    printf("%f\n", strtof(str, NULL));
    return 1;
}
Run Code Online (Sandbox Code Playgroud)

用-Wall编译:

test4.c:7: warning: implicit declaration of function âstrtofâ
Run Code Online (Sandbox Code Playgroud)

Mic*_*urr 8

您正在构建什么平台?你说的警告正在发出:

test4.c:7: warning: implicit declaration of function âstrtofâ
Run Code Online (Sandbox Code Playgroud)

表示编译器不知道strtof()返回一个浮点数,因此它将推int送到printf()调用而不是a double. strtof()通常声明stdlib.h,你包括.但它在C99之前不是标准函数,因此确切的编译器平台(以及您正在使用的配置/选项)可能会影响它是否可用.