"Robert Gamble" <rg*******@gmail.comwrites:
Eric Sosman wrote:
>Chris McDonald wrote:
po**********@gmail.com writes:
How i can convert *char to float?
atof();
strtod() is better, but neither actually converts a
string to float: both convert to double. The only way I
can think of to convert directly to float is
if (sscanf(my_string, "%f", &float_variable) == 1)
C99 has strtof() which will convert directly to float representation.
And if your implementation doesn't have strtof(), it's easy enough to
call strtod() and assign the result to a float. It's even easier to
use double in the first place.
sscanf() has the disadvantage that, if the floating-point literal in
the string represents a value that can't be represented in the target
type, the behavior is undefined. strtod() has well-defined behavior
on overflow. (It would have been nice if sscanf() had been defined
this way as well.)
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.