Archived

This topic is now archived and is closed to further replies.

SarsDP

string to float

Recommended Posts

Guest Anonymous Poster
I would''ve done it using atof, but the man page said it was deprecated and to use strtod.


char *s = ...;
char *end;
double d;

d = strtod(s, &end);

if (s == c) { /* no conversion */ }
else if (errno == ERANGE) { /* overflow/underflow */ }
else { /* d is valid */ }


This assumes errno isn''t set before invoking this code section.

Share this post


Link to post
Share on other sites