strtod 将字符串转换成浮点数

头文件

#include <stdlib.h>

语法

double strtod( const char *start, char **end );

功能

函数返回带符号的字符串 start 所表示的浮点型数。字符串 end 指向所表示的浮点型数之后的部分。如果溢出发生,返回HUGE_VAL 或 -HUGE_VAL。

示例

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

int main(void)
{
    char input[80], *endptr;
    double value;

    printf("Enter a floating point number:");
    gets(input);
    value = strtod(input, &endptr);
    printf("The string is %s the number is %lf\n", input, value);
    return 0;
}

输出结果:

Enter a floating point number:100
The string is 100 the number is 100.000000
关于
本网站属于个人的非赢利性网站,转载的文章遵循原作者的版权声明,如果原文没有版权声明,请来信告知:hxstrive@outlook.com
公众号