linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* strtod() and errno question.
@ 2006-01-10 21:42 J.
  2006-01-10 22:34 ` James Stevenson
  2006-01-11  3:01 ` Glynn Clements
  0 siblings, 2 replies; 4+ messages in thread
From: J. @ 2006-01-10 21:42 UTC (permalink / raw)
  To: linux-c-programming

Tuesday, January 10 22:35:50

Hi people,

I have a question regarding errno and strtod() error checking. I have a
function [listed below] that extracts a number from a string. In case of
an error, strerror() in conjunction with errno is used to display a user
friendly error message. However on a strtod() error; `Success' is
returned.

Error - strtod(ca4)`c': Success

Since I am a bit confused by the strtod() manual page, what would be the 
correct way to handle this ?

Thankx !

J.

int extrnumber(char *str) {
 int retv = 0;
 char *nptr = NULL;

 retv = strtod(str, &nptr);
 if(retv == 0 && nptr != NULL) {
  fprintf(stderr, "%s: Error - strtod(%s)`%c': %s\n", PACKAGE, 
    str, *nptr, strerror(errno));
  exit(EXIT_FAILURE);
 }

 return retv;
}


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-01-11 11:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-01-10 21:42 strtod() and errno question J.
2006-01-10 22:34 ` James Stevenson
2006-01-11  3:01 ` Glynn Clements
2006-01-11 11:24   ` J.

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).