converting a string into a double

后端 未结 4 1362
感动是毒
感动是毒 2020-12-12 00:28

I am looking for a way to get floating point input from a user.

My way of going about this is to use a self-made getstrn function and plug that into another function

4条回答
  •  一整个雨季
    2020-12-12 01:02

    Any of:

    • strtod()
    • atof()
    • sscanf()

    Of these sscanf offers the strongest validation, since the other two return a valid double value of 0.0 if the input cannot be interpreted as a double, while sscanf() returns the number of format specifiers successfully matched to the input. So:

    input_valid = (sscanf( arr, "%lf", value ) != 0 ) ;
    

提交回复
热议问题