What is the standard way to analyze floats at runtime in C?

I have a scientific application for which I want to enter initial values ​​at runtime. I have the opportunity to get them from the command line or get them from the input file. Any of these parameters is entered into a common parser, which uses strtod to return a linked list of initial values ​​for each simulation run. I either use the command line argument or getline () to read the values.

The question is, should I run my own parser, or should I use a parser generator or some library? What is the standard method? This is the only data that I will read at runtime, and everything else is set at compile time (except for the output files and a few other simple things).

Thank,

Joel

+3
source share
3 answers

Also check strtof () for float, strtod () for doubles.

+5
source
sscanf

probably the standard way to analyze them.

However, there are problems with sscanf, especially if you are parsing user input.

And of course,

atof
+3
source

, , (, , ..), (, , ..). , .

:
sscanf "" .

: , ( ). , strtof strtod - .

0

Source: https://habr.com/ru/post/1740778/


All Articles